带查询条件的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>
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>
相关文章推荐
- DMA传输详解
- Python操作Mysql数据库
- [转]jsonp详解
- oracle客户端可以连接但cmd连不上
- 关系型数据库操作
- ZooKeeper - Perl bindings for Apache ZooKeeper Perl绑定用于 Apache ZooKeeper
- java 99乘法表
- Linux查看CPU型号及内存频率及其它信息与清理内存的命令
- ZooKeeper - Perl bindings for Apache ZooKeeper Perl绑定用于 Apache ZooKeeper
- ZooKeeper - Perl bindings for Apache ZooKeeper Perl绑定用于 Apache ZooKeeper
- 1. PHP 图像处理
- 【C/C++】模拟实现strcpy的N种境界
- APUE 5-11 对各个标准I/O流打印缓冲状态信息
- 只要八步,就让你有面试机会!
- JSON两种结构之对象和数组的理解
- 微服务架构优缺点
- 如何禁用Visual Studio Browser Link
- VS插件
- 在Mybatis中操作表与表之间的关联的操作
- MSXML应用总结——概念篇