mybatis的通用Mapper函数库以及Example条件函数总结记录

一. 通用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)添加大于等于条件

参考博客:

  1. MyBatis Mapper3接口大全 :https://blog.csdn.net/wtopps/article/details/70232866
  2. Mybatis之Mapper接口及Example实例函数使用详解:https://blog.csdn.net/qushaming/article/details/83502345
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值