MyBatis-generator使用,Example缺少分页问题解决
一、分页问题
MyBatis自动生成代码没有分页功能。
如:
public class User {private Integer userId;private String name;public Integer getUserId() {return userId;}public void setUserId(Integer userId) {this.userId = userId;}public String getName() {return name;}public void setName(String name) {this.name = name;}
}pubilc class Test{public static void main(String[] args){UserExample user= new UserExample();user.createCriteria().andNameLike("%" + "zhansan" + "%");user.setOrderByClause("user_id asc");List<User> uList = userMapper.selectByExample(user);}}
二、解决方案
1、改写selectByExample方法和XML,增加分页字段;具有侵入性,下一次自动生成代码失效
2、新增分页查询@Select注解方法;需要额外的Mapper基接口
public interface UserMapper extends UserBaseMapper {
//... generate method
}public interface UserBaseMapper {@Select({"<script>","select u.user_id as userId, u.user_name as `name` ","from user u ","where 1=1 ","<if test=\"u!=null\"> "," <if test=\"u.userId!=null\"> "," and u.user_id=#{u.userId} "," </if>"," <if test=\"u.name!=null and u.name.length()>0\"> "," and u.`name`=#{u.name} "," </if> ","</if> "," limit #{index},#{limit}","</script>"})public List<User> select(@Param("u") User user, @Param("index") int index, @Param("limit") int limit);
}
3、改造Example的setOrderByClause()方法,使它支持分页
利用Mapper.xml的orderByClause使用$插值的方式,进行注入分页SQL limit
UserExample user= new UserExample();
user.createCriteria().andUserIdEqualTo(1);
user.setOrderByClause("user_id asc limit 0,20");//分页功能
List<User> uList = userMapper.selectByExample(user);
MyBatis-generator使用,Example缺少分页问题解决相关推荐
- MyBatis Generator如何实现MYSQL分页插件
前言 MyBatisGenerator是一个非常方便的代码生成工具,它能够根据表结构生成CRUD代码,可以满足大部分需求.但是唯一让人不爽的是,生成的代码中的数据库查询没有分页功能.本文介绍如何让My ...
- mysql分页取数每一页生成xml_让MyBatis Generator产生的代码支持分页
本文提供一种方法,让MyBatis Generator产生的代码支持分页, 适用于MySQL. 分析 如果要获取分页信息,使用MySQL语句,我们需要怎么做呢? select * from t_us ...
- MyBatis Generator分页插件RowBoundsPlugin坑
一.Mybatis Generator设置分页 Mybatis Generator没有设置分页,但自带了个RowBoundsPlugin分页插件,故而配置 <plugin type=" ...
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
我们这一一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池的好处我 ...
- MyBatis Criteria使用 OffsetLimitInterceptor.java分页报错
Reported by hbm...@gmail.com, Oct 28, 2010 MyBatis 3.0.2 ? 调用mapper的select方法,使用MyBatis Generator生成的C ...
- tkmbatis 日志_springboot+maven+tk.mybatis+generator逆向工程
1.父工程的pom.xml中导入依赖和插件,当前完整的文件如下: 4.0.0 com.sino demo_parent pom 1.0-SNAPSHOT bos org.springframework ...
- MyBatis Generator:[WARNING] Table Configuration users matched more than one table
MyBatis Generator:[WARNING] Table Configuration users matched more than one table #在使用 MyBatis Gener ...
- Mybatis generator配置
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE generatorConfigura ...
- mybatis generator 属性详解
2019独角兽企业重金招聘Python工程师标准>>> <?xml version="1.0" encoding="UTF-8"?> ...
最新文章
- linux下查看Mysql默认编码、修改默认编码
- Privoxy shadowscocks代理
- 题目1166:迭代求立方根
- Maven让资源文件处理插件能够解析资源文件中的Maven属性
- 测试晶面间距软件_超逼真动图解析常用15大分析测试仪器,必收藏!SEM, 红外,紫外,核磁,质谱,TEM,ICP等...
- 七牛2018春季校园招聘后端开发工程师笔试经验
- python设置图片透明度_学习python第40天
- mysql排序时设置主次_Mysql实现Rownum()排序后根据条件获取名次
- React Native获取设备信息组件
- mysql自增字段_MySQL自增字段的常用语句
- 10分钟带你学会微信小程序的反编译
- linux lvs 存储层,LVS集群配置之LVS介绍
- ext2 无损升级 ext3、ext4
- canpro脚本_周立功CANPro软件下载
- HTML表格之合并单元格
- 读林锐《软件工程思想》------讲述软件开发和做程序员的道理--语录
- K8S中的亲和,污点和容忍
- [N1CTF 2022] solve_pow,baby_N1ES
- Java汉字转换拼音工具类
- java实现图片反色
热门文章
- mysql判断是否在日期区间_通过sql判断时间区间是否存在数据
- neo4j 查询同一节点的两个上级_WhatRoute for Mac(互联网流量诊断查询工具)
- easyui datagrid 中怎么选中所有页面的数据_学会这5个Excel中常用技巧,可以准时下班去摆摊了...
- 高等数学下-赵立军-北京大学出版社-题解-练习8.3
- [蓝桥杯2019初赛]旋转-找规律
- 英语期末复习unit 1-2课后习题第一题及背诵段落
- matlab gui 密码登录 论文,MATLAB GUI 密码输入
- linux ps mysql_linux系统中ps指令使用详解
- CoreJava 笔记总结-第四章 对象与类
- HTMLCSS 超简单的前端设计入门-1!