SQL語句中的分頁。
首先在接口中定義,定義的時候是需要通過@Param注解來表示向mybatis里傳入參數:
public interface GoodsInfoMapper extends IDaoHotel<GoodsInfo> { //定義一個方法,這個方法來表示分頁的 List<GoodsInfo> getlistbypage(@Param("startindex")Integer startindex, @Param("endindex")Integer endindex, @Param("goodsInfo")GoodsInfo goodsInfo); }
緊接着在實體XML配置文件里寫:
<!-- 帶查詢條件和分頁的查詢方法 --> <select id="getlistbypage" resultMap="goodsInfoLazyResultMap"> select t.* from (select rownum as rnum, g.* from goodsinfo g where g.ifdelete='N' <if test="goodsInfo.goodstypeid!=null and goodsInfo.goodstypeid >0"> and g.goodstypeid=#{goodsInfo.goodstypeid} </if> <if test="goodsInfo.commdityid!=null and goodsInfo.commdityid!=''"> and g.commdityid=#{goodsInfo.commdityid} </if> <if test="goodsInfo.commdityname!=null and goodsInfo.commdityname!=''"> and g.commdityname=#{goodsInfo.commdityname} </if> )t <where> <if test="startindex!=null and startindex>0"> <![CDATA[ and t.rnum >=#{startindex} ]]> </if> <if test="endindex!=null and endindex>0"> <![CDATA[ and t.rnum <=#{endindex} ]]> </if> </where> </select>