초급코딩
2021-06-14 16:26:14
7
312

spring 관리자가 회원 글 강제 삭제 하는 법 알려주세요.


jsp


package com.icia.project.service;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.icia.project.dao.BoardDAO;
import com.icia.project.dao.MemberDAO;
import com.icia.project.dto.BoardDTO;
import com.icia.project.dto.PageDTO;

@Service
public class BoardService {

	@Autowired
	private BoardDAO bdao;
	private ModelAndView mav;

	// 글 쓰기
	public ModelAndView BoardWriter(BoardDTO board) throws IllegalStateException, IOException {
		System.out.println("sevice + boardwrtier : " + board);
		mav = new ModelAndView();
		MultipartFile bfile = board.getBfile();
		String bfilename = bfile.getOriginalFilename();
		bfilename = System.currentTimeMillis() + "-" + bfilename;
		String savePath = "D:\\Source_LEE\\string\\Project210609\\src\\main\\webapp\\resources\\upload\\" + bfilename;
		if (!bfile.isEmpty()) {
			bfile.transferTo(new File(savePath));
		}
		board.setBfilename(bfilename);
		bdao.BoardWriter(board);
		mav.setViewName("redirect:/paging");
		return mav;
	}

	// 페이징 목록
	// 페이징 처리에 활용할 상수
	private static final int PAGE_LIMIT = 5;
	private static final int BLOCK_LIMIT = 5;

	public ModelAndView BoardPaging(int page) {
		System.out.println("service + BoardPaging");
		mav = new ModelAndView();
		int listCount = bdao.ListCount();
		int startRow = (page - 1) * PAGE_LIMIT + 1;
		int endRow = page * PAGE_LIMIT;
		PageDTO paging = new PageDTO();
		paging.setStartRow(startRow);
		paging.setEndRow(endRow);
		System.out.println("paging값" + paging.toString());
		List<BoardDTO> boardList = bdao.BoardPaging(paging);
		int maxPage = (int) (Math.ceil((double) listCount / PAGE_LIMIT));
		int startPage = (((int) (Math.ceil((double) page / BLOCK_LIMIT))) - 1) * BLOCK_LIMIT + 1;
		int endPage = startPage + BLOCK_LIMIT - 1;
		if (endPage > maxPage) {
			endPage = maxPage;
		}
		System.out.println(boardList);
		paging.setPage(page);
		paging.setStartPage(startPage);
		paging.setEndPage(endPage);
		paging.setMaxPage(maxPage);
		mav.addObject("paging", paging);
		mav.addObject("boardList", boardList);
		mav.setViewName("Page");
		return mav;
	}

	// 글 상세 보기 + 조회수 증감
	public ModelAndView BoardView(int bnumber, int page) {
		System.out.println("service + boardview : " + bnumber);
		mav = new ModelAndView();
		bdao.BoardHite(bnumber);
		BoardDTO board = bdao.BoardView(bnumber);
		mav.addObject("board", board);
		mav.setViewName("BoardView");
		return mav;
	}

	// 글 수정 요청
	public ModelAndView BoardUpdate(int bnumber) {
		System.out.println("service + boardupdate : " + bnumber);
		mav = new ModelAndView();
		BoardDTO board = bdao.BoardUpdate(bnumber);
		mav.addObject("board", board);
		mav.setViewName("BoardUpdate");
		return mav;
	}

	// 글 수정 처리
	public ModelAndView UpdateProcess(BoardDTO board) throws IllegalStateException, IOException {
		System.out.println("service + updateprocess : " + board);
		mav = new ModelAndView();
		MultipartFile bfile = board.getBfile();
		String bfilename = bfile.getOriginalFilename();
		bfilename = System.currentTimeMillis() + "-" + bfilename;
		String savePath = "D:\\Source_LEE\\string\\Project210609\\src\\main\\webapp\\resources\\upload\\" + bfilename;
		if (!bfile.isEmpty()) {
			bfile.transferTo(new File(savePath));
		}
		board.setBfilename(bfilename);
		int updateResult = bdao.UdateProcess(board);
		if (updateResult > 0) {
			System.out.println("성공");
			mav.addObject("board", board);
			mav.setViewName("BoardView");
		} else {
			System.out.println("실패");
			mav.setViewName("redirect:/boardview?bnumber=" + board.getBnumber());
		}
		return mav;
	}

	// 내가 작성한 글 보기
	public ModelAndView MyWriteList(String bwriter) {
		System.out.println("service + MyWriteList : " + bwriter);
		mav = new ModelAndView();
		List<BoardDTO> boardList = bdao.MyWriteList(bwriter);
		mav.addObject("boardList", boardList);
		mav.setViewName("MyWriteList");
		return mav;
	}

	// 관리자 글 강제 삭제
	public ModelAndView mBoardDelete(int bnumber, String bwriter) {
		System.out.println("service + mBoardDelete : " + bnumber);
		mav = new ModelAndView();
		bdao.mBoardDelete(bnumber);
		mav.setViewName("redirect:/mywritelist");
		return mav;
	}

	// 글 삭제
	public ModelAndView BoardDelete(int bnumber) {
		System.out.println("service + boarddelete : " + bnumber);
		mav = new ModelAndView();
		bdao.BoardDelete(bnumber);
		mav.setViewName("redirect:/paging");
		return mav;
	}

	// 검색
	public ModelAndView BoardSearch(String searchType, String keyword, int page) {
		System.out.println("service + boardSearch : " + searchType +"+"+ keyword);
		mav = new ModelAndView();
		Map<String, String> searchMap = new HashMap<String, String>();
		searchMap.put("type", searchType);
		searchMap.put("word", keyword);
		List<BoardDTO> board = bdao.BoardSearch(searchMap);
		mav.addObject("boardList", board);
		
		// 게시글 수
		int listCount = bdao.ListCount();
		int startRow = (page - 1) * PAGE_LIMIT + 1;
		int endRow = page * PAGE_LIMIT;
		PageDTO paging = new PageDTO();
		paging.setStartRow(startRow);
		paging.setEndRow(endRow);
		int maxPage = (int) (Math.ceil((double) listCount / PAGE_LIMIT));
		int startPage = (((int) (Math.ceil((double) page / BLOCK_LIMIT))) - 1) * BLOCK_LIMIT + 1;
		int endPage = startPage + BLOCK_LIMIT - 1;
		if (endPage > maxPage) {
			endPage = maxPage;
		}
		paging.setPage(page);
		paging.setStartPage(startPage);
		paging.setEndPage(endPage);
		paging.setMaxPage(maxPage);
		mav.addObject("paging", paging);
		mav.setViewName("PageSearch");
		return mav;
	}

}



controlle


// 내가 작성한 글 보기
	@RequestMapping(value = "/mywritelist")
	public ModelAndView MyWriteList(@RequestParam(value = "mid", required = false) String bwriter) {
		System.out.println("controller + MyWriteList : " + bwriter);
		mav = bs.MyWriteList(bwriter);
		return mav;
	}

	// 관리자 글 강제 삭제
	@RequestMapping(value = "/mboarddelete")
	public ModelAndView mBoardDelete(@RequestParam("bnumber") int bnumber,
									@RequestParam(value = "mid", required = false) String bwriter) {
		System.out.println("controller + mBoardDelete : " + bnumber);
		mav = bs.mBoardDelete(bnumber,bwriter);
		return mav;
	}



service


// 내가 작성한 글 보기
	public ModelAndView MyWriteList(String bwriter) {
		System.out.println("service + MyWriteList : " + bwriter);
		mav = new ModelAndView();
		List<BoardDTO> boardList = bdao.MyWriteList(bwriter);
		mav.addObject("boardList", boardList);
		mav.setViewName("MyWriteList");
		return mav;
	}

	// 관리자 글 강제 삭제
	public ModelAndView mBoardDelete(int bnumber, String bwriter) {
		System.out.println("service + mBoardDelete : " + bnumber);
		mav = new ModelAndView();
		bdao.mBoardDelete(bnumber);
		mav.setViewName("redirect:/mywritelist");
		return mav;
	}



dao


// 내가 작성한 글 보기
	public List<BoardDTO> MyWriteList(String bwriter) {
		System.out.println("bdao + MyWriteList : " + bwriter);
		return sql.selectList("bm.boardwritelist", bwriter);
	}

	// 관리자 글 강제 삭제
	public void mBoardDelete(int bnumber) {
		System.out.println("bdao + mBoardDelete : "+ bnumber);
		sql.delete("bm.mboarddelete",bnumber);
	}



mapper


<!-- 관리자 글 강제 삭제 -->
	<delete id="mboarddelete" parameterType="int">
		DELETE FROM BOARD210608
		WHERE BNUMBER=#{bnumber}
	</delete>

	<!-- 글 삭제 -->
	<delete id="boarddelete" parameterType="int">
		DELETE FROM BOARD210608
		WHERE BNUMBER=#{bnumber}
	</delete>


오류

500

Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='bwriter', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting null for parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 부적합한 열 유형: 1111


삭제는 되는데 페이지 표시가 되지 않습니다!!!ㅜㅜ


-2
0
  • 답변 7

  • 오후
    3k
    2021-06-14 16:43:04

    Could not set parameters for mapping: ParameterMapping{property='bwriter', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. 

    로직보면 관리자가 글삭제후 mywritelist 로가는데 해당페이지는 bwriter 값이있어야합니다.


    
    	// 관리자 글 강제 삭제
    	public ModelAndView mBoardDelete(int bnumber, String bwriter) {
    		System.out.println("service + mBoardDelete : " + bnumber);
    		mav = new ModelAndView();
    		bdao.mBoardDelete(bnumber);
    		mav.setViewName("redirect:/mywritelist");
    		return mav;
    	}
    
    
    
    	// 내가 작성한 글 보기
    	public ModelAndView MyWriteList(String bwriter) {
    		System.out.println("service + MyWriteList : " + bwriter);
    		mav = new ModelAndView();
    		List<BoardDTO> boardList = bdao.MyWriteList(bwriter);
    		mav.addObject("boardList", boardList);
    		mav.setViewName("MyWriteList");
    		return mav;
    	}
    
    
    
    
    
  • visualkhh
    4k
    2021-06-14 16:43:34

    TypeException: Could not set parameters for mapping


    null 들어가서 그렇습니다.

    #{id, jdbcType=VARCHAR}

  • 초급코딩
    2021-06-14 16:58:38

    bwriter 값 어떻게 넣나요???



    -2
  • 빌리언네어
    180
    2021-06-14 17:10:32 작성 2021-06-14 17:40:08 수정됨

    service 단에 modelAndView 가 있어야하는건가요?? DAO 단처럼 그냥메소드만 있어도 되지않나요??


    삭제는 되겠죠 Mapper까지 접근은 했으니깐 Service 단에서  modelandview 를 리턴하니 controller 단에서 받지를 못하고 그러니 저런 표시가 뜨는겁니당~

  • 웹개발자해보자
    188
    2021-06-14 17:32:25

    리다이렉트에 bwriter를 추가하면 되지않나요?

  • 초급코딩
    2021-06-14 17:55:41

    bwriter 을 어떻게 리다이렉트에 추가 하나요?

    -2
  • 웹개발자해보자
    188
    2021-06-14 23:27:24
    mav.setViewName("redirect:/mywritelist?bwriter="+bwriter);
    이런식으로 하면되지않나요
  • 로그인을 하시면 답변을 등록할 수 있습니다.