MyBatis的Mapper接口以及Example的实例函数及详解

来源:互联网 发布:狸窝mp4视频转换器mac 编辑:程序博客网 时间:2024/05/29 18:25

原文地址:  http://blog.csdn.net/biandous/article/details/65630783


一、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实例解析

mybatis的逆向工程中会生成实例及实例对应的example,example用于添加条件,相当where后面的部分 
xxxExample example = new xxxExample(); 
Criteria criteria = new Example().createCriteria();

方法说明example.setOrderByClause(“字段名 ASC”);添加升序排列条件,DESC为降序example.setDistinct(false)去除重复,boolean型,true为选择不重复的记录。criteria.andXxxIsNull添加字段xxx为null的条件criteria.andXxxIsNotNull添加字段xxx不为null的条件criteria.andXxxEqualTo(value)添加xxx字段等于value条件criteria.andXxxNotEqualTo(value)添加xxx字段不等于value条件criteria.andXxxGreaterThan(value)添加xxx字段大于value条件criteria.andXxxGreaterThanOrEqualTo(value)添加xxx字段大于等于value条件criteria.andXxxLessThan(value)添加xxx字段小于value条件criteria.andXxxLessThanOrEqualTo(value)添加xxx字段小于等于value条件criteria.andXxxIn(List<?>)添加xxx字段值在List<?>条件criteria.andXxxNotIn(List<?>)添加xxx字段值不在List<?>条件criteria.andXxxLike(“%”+value+”%”)添加xxx字段值为value的模糊查询条件criteria.andXxxNotLike(“%”+value+”%”)添加xxx字段值不为value的模糊查询条件criteria.andXxxBetween(value1,value2)添加xxx字段值在value1和value2之间条件criteria.andXxxNotBetween(value1,value2)添加xxx字段值不在value1和value2之间条件
阅读全文
0 0
原创粉丝点击