Issue
I encountered the following error during the posting paging process. I don't even use an array, but I don't know why I get this error. How can I solve this?
BoardCriteria is an object that stores the information needed to page the bulletin list.
java.lang.IndexOutOfBoundsException: Index 16 out of bounds for length 10
controller
// http://localhost:8088/club/{club_no}/boards
// http://localhost:8088/club/1/boards
@RequestMapping(value = "/{club_no}/boards", method = RequestMethod.GET)
public String boardListAllGet(@PathVariable("club_no") Integer club_no, Model model, BoardCriteria cri) {
log.info("club_no : "+club_no);
List<BoardTotalBean> boardList = service.getBoardListAll(club_no, cri);
log.info("@@@@@@@@@@@@"+boardList.get(16)+"");
model.addAttribute("club_no", club_no);
model.addAttribute("boardList", service.getBoardListAll(club_no, cri));
//BoardPageMaker pageMarker = new BoardPageMaker();
//pageMarker.setCri(cri);
//pageMarker.setTotalCount(service.getTotalBoardCnt());
//log.info(pageMarker+"");
//model.addAttribute("pm", pageMarker);
return "/club/boards/boardList";
}
mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.joinus.mapper.ClubMapper">
<resultMap type="MembersVo" id="membersMap">
<id property="member_no" column="member_no"/>
<id property="member_email" column="member_email"/>
<id property="member_pass" column="member_pass"/>
<id property="member_name" column="member_name"/>
<id property="member_location" column="member_location"/>
<id property="member_tel" column="member_tel"/>
<id property="member_image" column="member_image"/>
<id property="member_regdate" column="member_regdate"/>
<id property="member_updatedate" column="member_updatedate"/>
<id property="member_authority" column="member_authority"/>
<id property="member_signup_type" column="member_signup_type"/>
<id property="member_status" column="member_status"/>
<id property="member_role" column="member_role"/>
<id property="member_type" column="member_type"/>
<id property="member_location" column="member_location"/>
</resultMap>
<resultMap type="ClubBoardsVo" id="clubBoardsMap">
<id property="club_board_no" column="club_board_no"/>
<id property="club_no" column="club_no"/>
<id property="board_type_no" column="board_type_no"/>
<id property="member_no" column="member_no"/>
<id property="club_board_title" column="club_board_title"/>
<id property="club_board_content" column="club_board_content"/>
<id property="club_board_image" column="club_board_image"/>
<id property="club_board_date" column="club_board_date"/>
<id property="club_board_updatedate" column="club_board_updatedate"/>
<id property="club_board_likecnt" column="club_board_likecnt"/>
<id property="club_board_commentcnt" column="club_board_commentcnt"/>
</resultMap>
<resultMap type="BoardTotalBean" id="boardListMap">
<collection property="membersVo" resultMap="membersMap"/>
<collection property="clubBoardsVo" resultMap="clubBoardsMap" />
</resultMap>
<select id="getBoardListAll" resultMap="boardListMap">
<![CDATA[
select b.club_board_no, m.member_name, m.member_image, b.club_board_title, b.club_board_content, b.club_board_image, b.club_board_date, b.club_board_updatedate, b.club_board_likecnt, b.club_board_commentcnt
from club_boards b
join members m
on (b.member_no = m.member_no)
where b.club_no = #{club_no}
order by club_board_no desc
limit #{pageStart}, #{perPageNum}
]]>
</select>
<select id="totalBoardCnt" resultType="java.lang.Integer">
select count(club_board_no) from club_boards
</select>
</mapper>
DAOImpl
package com.joinus.persistence;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.apache.ibatis.session.SqlSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import com.joinus.domain.BoardCommentsVo;
import com.joinus.domain.BoardCriteria;
import com.joinus.domain.BoardLikesVo;
import com.joinus.domain.BoardTotalBean;
import com.joinus.domain.ClubBoardsVo;
import com.joinus.domain.ClubMembersVo;
import com.joinus.domain.ClubTotalBean;
import com.joinus.domain.ClubsVo;
import com.joinus.domain.Criteria;
import com.joinus.domain.MembersVo;
@Repository
public class ClubDaoImpl implements ClubDao{
@Inject
private SqlSession sqlSession;
static final String NAMESPACE ="com.joinus.mapper.ClubMapper";
public List<BoardTotalBean> getBoardListAll(Integer club_no, BoardCriteria cri) {
log.info("@@@@@@"+club_no+", "+cri);
Map<String, Object> param = new HashMap<String, Object>();
param.put("club_no", club_no);
param.put("pageStart", cri.getPageStart());
param.put("perPageNum", cri.getPerPageNum());
return sqlSession.selectList(NAMESPACE+".getBoardListAll", param);
}
}
BoardCriteria
package com.joinus.domain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BoardCriteria {
private static final Logger log = LoggerFactory.getLogger(BoardCriteria.class);
private int page;
private int perPageNum;
public BoardCriteria() {
this.page = 1;
this.perPageNum = 10;
}
public void setPage(int page) {
if(page <= 0) {
this.page = 1;
return;
}
this.page = page;
}
public void setPerPageNum(int perPageNum) {
if(perPageNum <=0 || perPageNum > 100) {
this.perPageNum = 10;
return;
}
this.perPageNum = perPageNum;
}
public int getPageStart() {
return (this.page - 1) * perPageNum;
}
public int getPage() {
return page;
}
public int getPerPageNum() {
return perPageNum;
}
// alt shift s + s
@Override
public String toString() {
return "BoardCriteria [page=" + page + ", perPageNum=" + perPageNum + "]";
}
}
Solution
It seems there is a limit of 10 in BoardCriteria:
public BoardCriteria() {
this.page = 1;
this.perPageNum = 10;
}
This might pose a problem when you attempt to access item 16:
List<BoardTotalBean> boardList = service.getBoardListAll(club_no, cri);
log.info("@@@@@@@@@@@@"+boardList.get(16)+"");
Answered By - morsor
Answer Checked By - David Marino (JavaFixing Volunteer)