게시물 삭제하기

·2024년 11월 8일

스프링

목록 보기
21/33

보드 딜리트 페이지 가젼오디

	@RequestMapping(value="boardDelete.aws")
	public String boardDelet(@RequestParam("bidx") int bidx,Model model){
		
		model.addAttribute("bidx",bidx);
		String path="WEB-INF/board/boardDelete";
		return path;
	}
  1. 삭제하기 화면 구현 기능
	// 삭제하기 기능
	@RequestMapping(value="boardDeleteAction.aws", method=RequestMethod.POST)
	public String boardDeleteAction(
			@RequestParam("bidx") int bidx, 
			@RequestParam("password") String password,
			HttpSession session
			){
		
		int midx = Integer.parseInt(session.getAttribute("midx").toString());
		boardService.boardDelete(bidx,midx,password);
		
		String path = "redirect:/board/boardList.aws";
			
	
		return path;
		}
  1. 컨트롤러에 가서 메서드를 우선 만들어 두기~~

public int boardDelete(int bidx, int midx, String password);
2., 서비스 가기

  1. impl가서 구현시키기

public int boardDelete(HashMap hm);
4. 매개변수에 가ㅓㅄ을 여러개를 담아야 하기 때문에 이럴때는 스프링에서 해쉬맵으로 값을 보낸다. 보드매펄에는 해쉬맵으로 매개변수를 넣는다.

	@Override
	public int boardDelete(int bidx, int midx, String password) {
		
		HashMap<String,Object> hm = new HashMap<String,Object>();
		hm.put("bidx", bidx);
		hm.put("midx", midx);
		hm.put("password", password);
		
		int cnt = bm.boardDelete(hm);
		return cnt;
	}
  1. impl로 돌아와서 자ㅣㄱ성하기
<!-- 게시물 삭제하는 쿼리 구문 -->
<update id="boardDelete" parameterType="HashMap">
update board set delyn='Y', modifyday=now() where bidx= #{bidx} and midx=#{midx} and password=#{password}
</update>
  1. 보드매퍼xml가서 구문 만ㅇ들기

  1. 서블릿xml에 로그인 거쳐가라는 거 인증1! 세션값을 꺼냈으니까 인터셉터 추가해주기
// 삭제하기 기능
	@RequestMapping(value="boardDeleteAction.aws", method=RequestMethod.POST)
	public String boardDeleteAction(
			@RequestParam("bidx") int bidx, 
			@RequestParam("password") String password,
			HttpSession session,
			RedirectAttributes rttr
			){
		
		BoardVo bv = boardService.boardSelectOne(bidx);
	      int midx = Integer.parseInt(session.getAttribute("midx").toString());
	      int value = boardService.boardDelete(bidx,midx,password);
	      
	      String path = "";
	      if(bv.getMidx()==midx) {
	         if(value==1) {
	            path = "redirect:/board/boardList.aws";
	         }else {
	            rttr.addFlashAttribute("msg", "비밀번호가 틀렸습니다.");
	            path = "redirect:/board/boardDelete.aws?bidx="+bidx;
	         }
	      }else {
	         rttr.addFlashAttribute("msg", "글을 쓴 회원이 아닙니다.");
	         path = "redirect:/board/boardDelete.aws?bidx="+bidx;
	      }

	      return path;  // .jsp는 WEB-INF/spring/appServlet/servlet-context.xml > 에서 붇어짐
	}
  1. 컨트롤러에 가서 if구문으로 예외처리 해주기

0개의 댓글