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>