Ucho
130
2019-07-18 16:40:56
6
503

게시판 페이징 구현하고나서 게시물 리스트에 접근이 불가능해요 ...


에러 읽어보니 cp쪽이 문제라고하는데 자세하게 어떤쪽인지 잘모르겟어요 ...

sqlMap.xml

<select id="bbsList" parameterType="HashMap" resultType="bbs.model.BbsDTO">	
  		select * from  
  		(select rownum as rnum, a.* from 
  		(select * from BT_TEXT order by tindex desc) a) b 
  		where rnum<![CDATA[>=]]>#{startnum} and rnum<![CDATA[<=]]>#{endnum}
  	</select>
  	<select id="bbsTotalCnt" resultType="java.lang.Integer">
  		select count(*) from BT_TEXT
  	</select>

DAOImple.java

public int getTotalCnt() 
	{

		int count = sqlMap.selectOne("bbsTotalCnt");
		return count;
	}

	public List bbsList(int cp, int ls) 
	{
		int startnum=(cp-1)*ls+1;
		int endnum=cp*ls;
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("startnum", startnum);
		map.put("endnum", endnum);
		List lists=sqlMap.selectList("bbsList", map);
		return lists;
	}

Controller

@RequestMapping("/bbsList.BT")
	public ModelAndView bbsList(int cp) 
	{
		ModelAndView mav=new ModelAndView();
		
		int totalcnt=bbsDao.getTotalCnt();
		int ls=5;
		int pagesize=5;
	
		List lists=bbsDao.bbsList(cp,ls);
		
		String pagename="bbsList.BT";
		
		String pageStr=makePage(pagename, totalcnt, ls, pagesize, cp);
		
		mav.addObject("lists", lists);
		mav.addObject("pageStr", pageStr);
		mav.setViewName("bbs/bbs_List");
		return mav;
	}

public static String makePage(String pagename, int totalcnt, int listsize, int pagesize, int cp) {

		int totalpage = (totalcnt / listsize) + 1;
		if (totalcnt % listsize == 0)
			totalpage--;

		int userGroup = cp / pagesize;
		if (cp % pagesize == 0)
			userGroup--;

		StringBuffer sb = new StringBuffer();

		if (userGroup != 0) 
		{

			sb.append("<a href='");
			sb.append(pagename);
			sb.append("?cp=");
			int priGroup = (userGroup - 1) * pagesize + pagesize;
			sb.append(priGroup);
			sb.append("'>&lt;&lt;</a>");

		}

		for (int i = (userGroup * pagesize + 1); i <= (userGroup * pagesize + pagesize); i++) {

			sb.append("&nbsp;&nbsp;");
			sb.append("<a href='");
			sb.append(pagename);
			sb.append("?cp=");
			sb.append(i);
			sb.append("'>");
			sb.append(i);
			sb.append("</a>");
			sb.append("&nbsp;&nbsp;");

			if (i == totalpage) {
				break;

			}
		}

		if (userGroup != (totalpage / 5) - (totalpage % 5 == 0 ? 1 : 0)) {

			sb.append("<a href='");
			sb.append(pagename);
			sb.append("?cp=");
			int netGroup = (userGroup + 1) * pagesize + 1;
			sb.append(netGroup);
			sb.append("'>&gt;&gt;</a>");
		}
		return sb.toString();
	}

bbs_List.jsp (페이징 표시하는 부분)
<tfoot>
	<tr>
		<td>
		<div style="text-align: center;">${requestScope.pageStr}</div>
		</td>
	</tr>
</tfoot>


에러
심각: Servlet.service() for servlet [dispatcher] in context with path [/BT-Plan] threw exception [Request processing failed; nested exception is org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public org.springframework.web.servlet.ModelAndView controller.BbsController.bbsList(int)]; nested exception is java.lang.IllegalStateException: Optional int parameter 'cp' is not present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.] with root cause
java.lang.IllegalStateException: Optional int parameter 'cp' is not present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.checkValue(HandlerMethodInvoker.java:750)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestParam(HandlerMethodInvoker.java:518)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:355)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
	at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:660)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:808)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)


0
  • 답변 6

  • 지나가던신입
    528
    2019-07-18 16:52:56

    int값을 파라미터로 받을때에는 null이 넘어오면 저 오류가 뜨는걸로 알고있습니다.

    아마 cp값이 안넘어오는것같은데용?

  • 수강권
    313
    2019-07-18 16:53:37
  • Ucho
    130
    2019-07-18 17:17:36

    문제 해결했습니다 

    제가 구현 다하고나서 신입님 말씀대로 

    경로에 ?cp=을 추가를 해줫어야했는데 추가하니까 바로 구현됬어요 

    항상 파라미터 값넘길때 넘어가는지 확인해야겟네요 ... 자주하는 실수가 되버렷네여


  • 지나가던신입
    528
    2019-07-18 17:19:10

    대부분 오류메세지에 null이라는 단어가 들어가면 파라미터문제인 경우가 대다수더라구요ㅎㅎ

  • Ucho
    130
    2019-07-18 18:39:53

    아앗! 감사합니다.. 아직 댓글구현 게시글/작성자 검색도 있는데 얼른해봐야죠 ... 조에서 제일쉬운거 받아서제일 오래걸리고있어서 많이 힘드네요 ..ㅠㅠ

  • 지나가던신입
    528
    2019-07-18 19:00:47

    언제든지 물어보셔요 저도 많이 부족하지만 보면 댓글 열심히 달아드릴게용

  • 로그인을 하시면 답변을 등록할 수 있습니다.