[mybatis]Record与Example的用法

一、Record

一个Record是一个Dao对象(继承Mapper接口),tkmybatis会将record自动映射成sql语句,record中所有非null的属性都作为sql语句,如:

映射的sql文如下:

SELECT eigyousyo_id,goods_id,goods_kind_id,goods_management_id,goods_management_name,reserve1,reserve2,reserve3,reserve4,sort_no,update_author,update_time,version
FROM mst_GoodsInPad
WHERE eigyousyo_id = ?

Mapper接口中的方法:

 

Mapper接口中部分方法的解析:

方法功能说明
int countByExample(UserExample example) thorws SQLException按条件计数
int deleteByPrimaryKey(Integer id) thorws SQLException按主键删除
int deleteByExample(UserExample example) thorws SQLException按条件查询
String/Integer insert(User record) thorws SQLException插入数据(返回值为ID)
User selectByPrimaryKey(Integer id) thorws SQLException按主键查询
ListselectByExample(UserExample example) thorws SQLException按条件查询
ListselectByExampleWithBLOGs(UserExample example) thorws SQLException按条件查询(包括BLOB字段)。只有当数据表中的字段类型有为二进制的才会产生。
int updateByPrimaryKey(User record) thorws SQLException按主键更新
int updateByPrimaryKeySelective(User record) thorws SQLException按主键更新值不为null的字段
int updateByExample(User record, UserExample example) thorws SQLException按条件更新
int updateByExampleSelective(User record, UserExample example) thorws SQLException按条件更新值不为null的字段

 

二、Example

Example对象允许在sql操作时手动指定where 条件:

映射的sql文会自动生成where 条件:

WHERE ( goods_code = goodsFromTable.getGoodsCode() )

Example的实例函数如下:

方法说明
example.setOrderByClause(“字段名 ASC”);添加升序排列条件,DESC为降序
example.setDistinct(false)去除重复,boolean型,true为选择不重复的记录。
criteria.andIsNull添加字段为null的条件
criteria.andIsNotNull添加字段不为null的条件
criteria.andEqualTo(value)添加字段等于value条件
criteria.andNotEqualTo(value)添加字段不等于value条件
criteria.andGreaterThan(value)添加字段大于value条件
criteria.andGreaterThanOrEqualTo(value)添加字段大于等于value条件
criteria.andLessThan(value)添加字段小于value条件
criteria.andLessThanOrEqualTo(value)添加字段小于等于value条件
criteria.andIn(List<?>)添加字段值在List<?>条件
criteria.andNotIn(List<?>)添加字段值不在List<?>条件
criteria.andLike(“%”+value+”%”)添加字段值为value的模糊查询条件
criteria.andNotLike(“%”+value+”%”)添加字段值不为value的模糊查询条件
criteria.andBetween(value1,value2)添加字段值在value1和value2之间条件
criteria.andNotBetween(value1,value2)添加字段值不在value1和value2之间条件

转载于:https://www.cnblogs.com/vickylinj/p/9486098.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值