프로젝트를 하면서 계속해서 궁금했던 JSP와 react에서의 데이터 불러오는 api의 차이점과 @RequestParam과 @PathVariable의 차이점을 알아보고자 작성하는 글
1차프로젝트
- 전자도서관 웹사이트 구축
- 기술스택 : spring, jsp
//게시글검색
@RequestMapping(value = "/notice/search", method = RequestMethod.GET)
public String searchadmin(Model model, PageDTO pv, @RequestParam("option") String option,
@RequestParam("searchword") String searchword) {
List<NoticeDTO> dtos = null;
// 페이지네이션을 위한 결과 개수 가져오기
int totalCount = userNoticeService.searchCountProcess(option, searchword);
model.addAttribute("totalCount", totalCount);
if (totalCount >= 1) {
if (pv.getCurrentPage() == 0)
pv.setCurrentPage(1);
this.pdto = new PageDTO(pv.getCurrentPage(), totalCount, searchword, option);
model.addAttribute("searchPv", this.pdto); //검색결과에 맞춘 pv 추가
model.addAttribute("Number", pdto.getNumber()); // 번호 추가
dtos = userNoticeService.searchListProcess(this.pdto);
model.addAttribute("aList", dtos); //검색 결과 리스트 추가
}
model.addAttribute("query",searchword); //검색어
model.addAttribute("option",option); //검색 옵션
return "notice/notice";
}
//공지사항 게시글 보기
@RequestMapping("/notice/info")
public ModelAndView viewExcute(@ModelAttribute("pv") PageDTO pv, int num, ModelAndView mav) {
NoticeDTO bdto = userNoticeService.contentProcess(num);
mav.addObject("dto", bdto); //게시글내용
mav.addObject("pn", userNoticeService.preNextProcess(num)); //이전글,다음글
mav.addObject("currentPage", pv.getCurrentPage());
mav.setViewName("notice/view");
return mav;
}
2차프로젝트
- 캠핑장 예약, 캠핑용품 쇼핑 웹사이트 구축
- 기술스택 : spring boot, react
//전체 캠핑용품 조회 + 검색
@GetMapping("/admin/prod/prodlist/{currentPage}")
public Map<String, Object> selectAllUser(@RequestParam ("startDate") String startDate,@RequestParam ("endDate") String endDate, @RequestParam ("state") String state, @RequestParam ("category")String category, @RequestParam ("searchKey")String searchKey, @RequestParam ("searchWord")String searchWord, PageDTO pv, @PathVariable("currentPage") int currentPage) {
Map<String, Object> map = new HashMap<>();
Map<String, String> search = new HashMap<String, String>();
search.put("startDate", startDate);
search.put("endDate", endDate);
search.put("state", state);
search.put("category", category);
search.put("searchKey", searchKey);
search.put("searchWord", searchWord);
int totalRecord = prodService.searchProdCountProcess(search);
System.out.println("totalRecord : "+totalRecord);
if(totalRecord>=1) {
if(pv.getCurrentPage()==0)
this.currentPage=currentPage;
else
this.currentPage = pv.getCurrentPage();
this.pdto = new PageDTO(this.currentPage, totalRecord, startDate, endDate, state, category, searchKey, searchWord);
System.out.println("currentPage Check : "+currentPage);
map.put("prodList", prodService.searchProdListProcess(this.pdto));
map.put("pv", this.pdto);
}
return map;
}
@PathVariable
("currentPage") int currentPage과 @RequestParam
("searchWord") String searchWord을 같이 사용할 수 있음!
//상품상세
@GetMapping("/admin/prod/detail/{prodKeyNum}")
public ProdDTO viewExcute(@PathVariable("prodKeyNum") String prodKeyNum) {
return prodService.detailProdProcess(prodKeyNum);
}