웹프로젝트
MongoDB query 작성 (JPA)
Hilu
2019. 5. 2. 22:29
참고 : https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/
Spring Data MongoDB - Reference Documentation
As of version 3.6, MongoDB supports the concept of sessions. The use of sessions enables MongoDB’s Causal Consistency model, which guarantees running operations in an order that respects their causal relationships. Those are split into ServerSession instan
docs.spring.io
JPA 를 활용하여 query 를 작성 하였다.
JPA는 정말 신세계 였다. 함수명을 통하여 query를 조작 할 수 있다는 것이 너무 신기 했다.
예제)
이렇게 얻은 데이터를 javaScript 에서 아래와 같이 chart 뿌려 줬다.
controller
@GetMapping("/chart")
public String chartView(@RequestParam("connectionDate") String date, Model model) throws ParseException {
// date 범위로 찾아서
List<ConnectionHistoryVO> result = this.boardService.getBoardListByDate(getDate(date));
// 시간 별로 분리 해서
List<Integer> chartData = generateCharData(result);
model.addAttribute("chartData", chartData);
return "sampleChart";
}
js
/* <![CDATA[ */
new Chart(document.getElementById("line-chart"), {
type: 'line',
data: {
labels: [00,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],
datasets: [{
data: /*[[${chartData}]]*/,
label: "접속 횟수",
borderColor: "#3e95cd",
fill: false
}
]
},
options: {
title: {
display: true,
text: '시간별 접속 현황'
}
}
});
/*]]>*/
결과