您的位置:首页 > 其它

带查询条件的Mybatis分页的实现

2016-07-19 09:39 585 查看
1)实现原理,在定义参数的时候,需要告诉Mybatis。这是一个参数。所以在定义接口中的方法的时候,它的参数的设定方式:

publicList<Cate> selectCateByPage(@Param("startNum")int startNum,@Param("pageSize") intpageSize,@Param("c")Cate c);

2)在SQL语句的实现的时候:需要对这些参数做设置。

  <!--带有分页查询条件的SQL语句 -->

    <select id="selectCateByPage"parameterType="com.gxa.bj.model.Cate"


   resultType="com.gxa.bj.model.Cate">

        Select * From cate

         where 1=1

       <if test="c.id>0">

          And id=#{c.id}

       </if>

       <if test="c.name!=null">

          And name like '%${c.name}%'

       </if>

       <iftest="c.description!=null">

          And description like'%${c.description}%'

       </if>

         limit #{startNum},#{pageSize}

    </select>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: