mybatis中Example的使⽤:条件查询、排序、分页(三种分
页⽅式:RowBound。。。
ity.Example;
import com.github.pagehelper.PageHelper;
...
@Override
public List<Repayxxx> listRepaymentPlan(Integer start) {
Example example = new Example(Repayxxx.class);
// 排序
// 条件查询
.andNotEqualTo("repayxxx", 3)
.andLessThanOrEqualTo("xxxRepayDate", new Date());
// 分页
PageHelper.startPage(start, 20); // 每次查询20条
return repaymentPlanMapper.selectByExample(example);
}
关于排序还有这些写法:
// 注意:排序使⽤的是表中的列名,不是对象属性名。
example.setOrderByClause("time DESC");
example.setOrderByClause ("product_code desc , product_name desc");
/
/ 注意:排序使⽤的是对象属性。
2. PageHelper 使⽤详解见⽂章:
3. 更多关于 Example 的使⽤说明见⽂章:
4. 当只是查询数据,不需要返回总条数时可选择此⽅法:
PageHelper.startPage(第⼏页, 20,false); // 每次查询20条
当数据量极⼤时,可以快速查询,忽略总条数的查询,减少查询时间。
以下是该⽅法原码实现:
-------------------------------------------------
2019.5.13 后记 :
1)分页的写法 下图中黄框中的写法运⾏ ⽐红框中 快,不知道是不是插件本⾝也会有费时:
2)再补充⼀种分页⽅式,mybatis ⾃带的 RowBounds:
public List<RepayPlan> listRepayPlan(int start) {
Example example = new Example(RepayPlan.class);
.andNotEqualTo("repayxxx", 3)
.andLessThanOrEqualTo("xxxRepayDate", new Date());
RowBounds rowBounds = new RowBounds(start, 20); // 每次查询20条
return epaymentPlanMapper.selectByExampleAndRowBounds(example,rowBounds);
分页查询插件}
推荐⽤ RowBounds :mybatis ⾃带的,且速度快 。个⼈运⾏,后 2 种分页明显⽐ PageHelper 快。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论