Mybatis里SQL語句的分頁


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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM