一. 通用Mapper接口方法
1. 查
方法 | 功能 |
---|---|
User selectByPrimaryKey(Integer id) throws SQLException | 按主键查询 |
List selectByExample(UserExample example) throws SQLException | 按条件查询,返回类型为List |
List selectByExampleWithBLOGs(UserExample example) throws SQLException | 按条件查询(包括BLOB字段)。只有当数据表中的字段类型包含二进制的才会产生。 |
List select(T record) | 根据实体中的属性值进行查询,查询条件使用等号 |
User selectOne(T record) | 选择一个查询 |
List selectOneByExample(UserExample example) | 按条件选择一个查询 |
selectAll() | 查询所有 |
selectCount(T record) | 根据实体中的属性查询总数,查询条件使用等号 |
selectCountByExample() | 按条件统计 |
selectByRowBounds(T record, RowBounds rowBounds) | 根据实体属性和RowBounds进行分页查询 |
selectByExampleAndRowBounds(Object example, RowBounds rowBounds) | 根据example条件和RowBounds进行分页查询 |
2. 插入
方法 | 功能 |
---|---|
String/Integer insert(User record) throws SQLException | 保存一个实体,null的属性也会保存,不会使用数据库默认值 |
String/Integer insertSelective(User record) throws SQLException | 保存一个实体,null的属性不会保存,会使用数据库默认值 |
3. 更新
方法 | 功能 |
---|---|
int updateByPrimaryKey(User record) throws SQLException | 按主键更新 |
int updateByPrimaryKeySelective(User record) throws SQLException | 按主键更新值不为Null的字段 |
int updateByExample(User record, UserExample example) throws SQLException | 按条件更新 |
int updateByExampleSelective(User record, UserExample example) throws SQLException | 按条件更新值不为Null的字段 |
4. 删除
方法 | 功能 |
---|---|
delete() | |
int deleteByPrimaryKey(Integer id) throws SQLException | 按主键删除 |
int deleteByExample(UserExample example) throws SQLException | 按条件删除 |
二. 条件Example criteria实例方法
Example o = new Example(Entity(实体类名).class);
Example.Criteria criteria = o.createCriteria();
Example
方法 | 功能 |
---|---|
example.setOrderByClause(“字段名 ASC”); | 添加升序排列条件,DESC为降序 |
example.createCriteria() | 创建Criteria实例后添加条件 |
example.setDistinct(boolean distinct) | 去除重复,参数为boolean型,true为选择不重复的记录 |
其余略。
Criteria
方法 | 功能 |
---|---|
andLike(String property, String value) | like模糊匹配 |
andNotLike(String property, String value) | 匹配非like条件 |
andEqualTo(Object param) | 等值匹配 |
andEqualTo(String property, Object value) | 等值匹配 |
andNotEqualTo(String property, Object value) | 不等匹配 |
andBetween(String property, Object value1, Object value2) | 字段在between之间匹配 |
andNotBetween(String property, Object value1, Object value2) | between之外匹配 |
andIn(String property, Iterable values) | 等价于SQL中的in条件 |
andNotIn(String property, Iterable values) | not in 匹配 |
andIsNotNull(String property) | 字段非空匹配 |
andIsNull(String property) | 空字段匹配 |
andLessThan(String property, Object value) | 添加小于条件 |
andLessThanOrEqualTo(String property, Object value) | 添加小于等于条件 |
andGreaterThan(String property, Object value) | 添加大于条件 |
andGreaterThanOrEqualTo(String property, Object value) | 添加大于等于条件 |
参考博客:
- MyBatis Mapper3接口大全 :https://blog.csdn.net/wtopps/article/details/70232866
- Mybatis之Mapper接口及Example实例函数使用详解:https://blog.csdn.net/qushaming/article/details/83502345
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/157311.html