-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathEgovSampleController.java
More file actions
96 lines (78 loc) · 3.31 KB
/
EgovSampleController.java
File metadata and controls
96 lines (78 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package egovframework.example.sample.web;
import javax.validation.Valid;
import org.egovframe.rte.fdl.property.EgovPropertyService;
import org.egovframe.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import egovframework.example.sample.service.EgovSampleService;
import egovframework.example.sample.service.SampleVO;
import lombok.RequiredArgsConstructor;
@Controller
@RequiredArgsConstructor
public class EgovSampleController {
/** EgovSampleService */
private final EgovSampleService sampleService;
/** EgovPropertyService */
private final EgovPropertyService propertiesService;
@GetMapping("/")
public String search(@ModelAttribute SampleVO sampleVO, Model model) throws Exception {
return this.list(sampleVO, model);
}
@PostMapping("/sample/list")
public String list(@ModelAttribute SampleVO sampleVO, Model model) throws Exception {
sampleVO.setPageUnit(propertiesService.getInt("pageUnit"));
sampleVO.setPageSize(propertiesService.getInt("pageSize"));
// pagination setting
PaginationInfo paginationInfo = new PaginationInfo();
paginationInfo.setCurrentPageNo(sampleVO.getPageIndex());
paginationInfo.setRecordCountPerPage(sampleVO.getPageUnit());
paginationInfo.setPageSize(sampleVO.getPageSize());
sampleVO.setFirstIndex(paginationInfo.getFirstRecordIndex());
sampleVO.setLastIndex(paginationInfo.getLastRecordIndex());
sampleVO.setRecordCountPerPage(paginationInfo.getRecordCountPerPage());
// List
model.addAttribute("resultList", sampleService.selectSampleList(sampleVO));
// Count
paginationInfo.setTotalRecordCount(sampleService.selectSampleListTotCnt(sampleVO));
// Pagination
model.addAttribute("paginationInfo", paginationInfo);
return "egovSampleList";
}
@PostMapping("/sample/detail")
public String detail(@ModelAttribute SampleVO sampleVO, @RequestParam String id, Model model) throws Exception {
sampleVO.setId(id);
SampleVO detail = this.sampleService.selectSample(sampleVO);
model.addAttribute("sampleVO", detail);
return "egovSampleRegister";
}
@GetMapping("/sample/add")
public String form(@ModelAttribute SampleVO sampleVO) {
return "egovSampleRegister";
}
@PostMapping("/sample/add")
public String add(@Valid @ModelAttribute SampleVO sampleVO, BindingResult bindingResult) throws Exception {
if (bindingResult.hasErrors()) {
return "egovSampleRegister";
}
this.sampleService.insertSample(sampleVO);
return "redirect:/";
}
@PostMapping("/sample/update")
public String update(@Valid @ModelAttribute SampleVO sampleVO, BindingResult bindingResult) throws Exception {
if (bindingResult.hasErrors()) {
return "egovSampleRegister";
}
this.sampleService.updateSample(sampleVO);
return "redirect:/";
}
@PostMapping("/sample/delete")
public String delete(@ModelAttribute SampleVO sampleVO) throws Exception {
this.sampleService.deleteSample(sampleVO);
return "redirect:/";
}
}