首先在对应的Mapper.xml中配置:
<!--查询总记录的条数-->
<select id="findTotal" resultType="java.lang.Integer">
SELECT COUNT(id) FROM Diary
</select>
<!--分页查询十条-->
<select id="pageShare" resultMap="seeShare">
SELECT * FROM Diary limit #{startRow},10
</select>
对应的Mapper中配置:
@Mapper//说明这是个一个mapper
public interface DiaryMapper {
public int insertDiary(Diary diary) throws Exception;
public List<Diary> selectShare();
public int findTotal();
public List<Diary> pageShare(int startRow);
}
DAO层调用Mapper查询:
//获得记录总数
public int findTotal(){
DiaryMapper diaryMapper = sqlSession.getMapper(DiaryMapper.class);
int total = diaryMapper.findTotal();
return tot