SearchBoardController.java > SPRING1

본문 바로가기

사이트 내 전체검색

뒤로가기 SPRING1

SearchBoardController.java

페이지 정보

작성자 관리자 작성일 24-07-31 18:09 조회 107 댓글 0

본문

package com.pkt.controller;


import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

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.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.mvc.support.RedirectAttributes;


import com.pkt.model.BoardVO;

import com.pkt.model.Criteria;

import com.pkt.model.PageMaker;

import com.pkt.service.BoardService;


import lombok.AllArgsConstructor;

import lombok.extern.log4j.Log4j;


@Controller

@Log4j

@RequestMapping("/sboard/")

@AllArgsConstructor

public class SearchBoardController {


private BoardService service;


@GetMapping("list")

public void list(@ModelAttribute("cri") Criteria cri, Model model) {

log.info(cri.toString());


model.addAttribute("list", service.listSearchCriteria(cri));


PageMaker pageMaker = new PageMaker();


pageMaker.setCri(cri);

pageMaker.setTotalCount(service.listSearchCount(cri));


model.addAttribute("pageMaker", pageMaker);

}


@GetMapping("read")

public void read(@RequestParam("bno") int bno, @ModelAttribute("cri") Criteria cri, Model model) {

PageMaker pageMaker = new PageMaker();

pageMaker.setCri(cri);

model.addAttribute("pageMaker", pageMaker);

model.addAttribute(service.readOne(bno));

}


@GetMapping("modify")

public void modifyGET(int bno, @ModelAttribute("cri") Criteria cri, Model model) {

model.addAttribute(service.readOne(bno));

}


@PostMapping("modify")

public String modifyPOST(BoardVO board, Criteria cri, RedirectAttributes rttr) {

log.info(cri.toString());


service.modify(board);


rttr.addAttribute("page", cri.getPage());

rttr.addAttribute("perPageNum", cri.getPerPageNum());

rttr.addAttribute("searchType", cri.getSearchType());

rttr.addAttribute("keyword", cri.getKeyword());

rttr.addFlashAttribute("msg", "modify");


log.info(rttr.toString());


return "redirect:/sboard/list";

}


@GetMapping("remove")

public String remove(@RequestParam("bno") int bno, Criteria cri, RedirectAttributes rttr) {

service.remove(bno);


rttr.addAttribute("page", cri.getPage());

rttr.addAttribute("perPageNum", cri.getPerPageNum());

rttr.addAttribute("searchType", cri.getSearchType());

rttr.addAttribute("keyword", cri.getKeyword());


rttr.addFlashAttribute("msg", "delete");


return "redirect:/sboard/list";

}


@GetMapping("register")

public void registGET() {

log.info("regist get ...........");

}


@PostMapping("register")

public String registPOST(BoardVO board, RedirectAttributes rttr) throws Exception {

log.info("regist post ...........");

log.info(board.toString());


service.regist(board);


rttr.addFlashAttribute("msg", "register");


return "redirect:/sboard/list";

}


// reply 추가

@GetMapping("reply")

public void ajaxTest() {

log.info("reply get ..........."); 

}


}

댓글목록 0

등록된 댓글이 없습니다.


Copyright © dancePKT. All rights reserved.
PC 버전으로 보기