美文网首页
mybatis之generator插件中example和reco

mybatis之generator插件中example和reco

作者: Apple_Boy | 来源:发表于2019-07-10 17:27 被阅读0次

一、Record

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

image

映射的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接口中的方法:

image

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 按主键查询
List selectByExample(UserExample example) thorws SQLException 按条件查询
List selectByExampleWithBLOGs(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 条件:

image

映射的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

相关文章

网友评论

      本文标题:mybatis之generator插件中example和reco

      本文链接:https://www.haomeiwen.com/subject/jpwckctx.html