下面是通用Mapper的各个方法描述,主要还是看官方的描述https://mapperhelper.github.io/all/。

基础接口

Select

接口:SelectMapper<T>
方法:List<T> select(T record);
说明:根据实体中的属性值进行查询,查询条件使用等号

接口:SelectByPrimaryKeyMapper<T>
方法:T selectByPrimaryKey(Object key);
说明:根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号

接口:SelectAllMapper<T>
方法:List<T> selectAll();
说明:查询全部结果,select(null)方法能达到同样的效果

接口:SelectOneMapper<T>
方法:T selectOne(T record);
说明:根据实体中的属性进行查询,只能有一个返回值,有多个结果是抛出异常,查询条件使用等号

接口:SelectCountMapper<T>
方法:int selectCount(T record);
说明:根据实体中的属性查询总数,查询条件使用等号

Insert

接口:InsertMapper<T>
方法:int insert(T record);
说明:保存一个实体,null的属性也会保存,不会使用数据库默认值

接口:InsertSelectiveMapper<T>
方法:int insertSelective(T record);
说明:保存一个实体,null的属性不会保存,会使用数据库默认值

Update

接口:UpdateByPrimaryKeyMapper<T>
方法:int updateByPrimaryKey(T record);
说明:根据主键更新实体全部字段,null值会被更新

接口:UpdateByPrimaryKeySelectiveMapper<T>
方法:int updateByPrimaryKeySelective(T record);
说明:根据主键更新属性不为null的值

Delete

接口:DeleteMapper<T>
方法:int delete(T record);
说明:根据实体属性作为条件进行删除,查询条件使用等号

接口:DeleteByPrimaryKeyMapper<T>
方法:int deleteByPrimaryKey(Object key);
说明:根据主键字段进行删除,方法参数必须包含完整的主键属性

base 组合接口

接口:BaseSelectMapper<T>
方法:包含上面Select的4个方法

接口:BaseInsertMapper<T>
方法:包含上面Insert的2个方法

接口:BaseUpdateMapper<T>
方法:包含上面Update的2个方法

接口:BaseDeleteMapper<T>
方法:包含上面Delete的2个方法

CRUD 组合接口

接口:BaseMapper<T>
方法:继承了base组合接口中的4个组合接口,包含完整的CRUD方法

Example 方法

接口:SelectByExampleMapper<T>
方法:List<T> selectByExample(Object example);
说明:根据Example条件进行查询
重点:这个查询支持通过Example类指定查询列,通过selectProperties方法指定查询列

接口:SelectCountByExampleMapper<T>
方法:int selectCountByExample(Object example);
说明:根据Example条件进行查询总数

接口:UpdateByExampleMapper<T>
方法:int updateByExample(@Param("record") T record, @Param("example") Object example);
说明:根据Example条件更新实体record包含的全部属性,null值会被更新

接口:UpdateByExampleSelectiveMapper<T>
方法:int updateByExampleSelective(@Param("record") T record, @Param("example") Object example);
说明:根据Example条件更新实体record包含的不是null的属性值

接口:DeleteByExampleMapper<T>
方法:int deleteByExample(Object example);
说明:根据Example条件删除数据

Example 组合接口

接口:ExampleMapper<T>
方法:包含上面Example中的5个方法

Condition 方法

Condition方法和Example方法作用完全一样,只是为了避免Example带来的歧义,提供的的Condition方法

接口:SelectByConditionMapper<T>
方法:List<T> selectByCondition(Object condition);
说明:根据Condition条件进行查询

接口:SelectCountByConditionMapper<T>
方法:int selectCountByCondition(Object condition);
说明:根据Condition条件进行查询总数

接口:UpdateByConditionMapper<T>
方法:int updateByCondition(@Param("record") T record, @Param("example") Object condition);
说明:根据Condition条件更新实体record包含的全部属性,null值会被更新

接口:UpdateByConditionSelectiveMapper<T>
方法:int updateByConditionSelective(@Param("record") T record, @Param("example") Object condition);
说明:根据Condition条件更新实体record包含的不是null的属性值

接口:DeleteByConditionMapper<T>
方法:int deleteByCondition(Object condition);
说明:根据Condition条件删除数据

Condition 组合接口

接口:ConditionMapper<T>
方法:包含上面Condition中的5个方法

RowBounds

默认为内存分页,可以配合PageHelper实现物理分页

接口:SelectRowBoundsMapper<T>
方法:List<T> selectByRowBounds(T record, RowBounds rowBounds);
说明:根据实体属性和RowBounds进行分页查询

接口:SelectByExampleRowBoundsMapper<T>
方法:List<T> selectByExampleAndRowBounds(Object example, RowBounds rowBounds);
说明:根据example条件和RowBounds进行分页查询

接口:SelectByConditionRowBoundsMapper<T>
方法:List<T> selectByConditionAndRowBounds(Object condition, RowBounds rowBounds);
说明:根据example条件和RowBounds进行分页查询,该方法和selectByExampleAndRowBounds完全一样,只是名字改成了Condition

RowBounds 组合接口

接口:RowBoundsMapper<T>
方法:包含上面RowBounds中的前两个方法,不包含selectByConditionAndRowBounds

special 特殊接口

这些接口针对部分数据库设计,不是所有数据库都支持

接口:InsertListMapper<T>
方法:int insertList(List<T> recordList);
说明:批量插入,支持批量插入的数据库可以使用,例如MySQL,H2等,另外该接口限制实体包含id属性并且必须为自增列

接口:InsertUseGeneratedKeysMapper<T>
方法:int insertUseGeneratedKeys(T record);
说明:插入数据,限制为实体包含id属性并且必须为自增列,实体配置的主键策略无效

MySQL 专用

接口:MySqlMapper<T>
继承方法:int insertList(List<T> recordList);
继承方法:int insertUseGeneratedKeys(T record);
说明:该接口不包含方法,继承了special中的InsertListMapper<T>InsertUseGeneratedKeysMapper<T>

SqlServer 专用

由于sqlserver中插入自增主键时,不能使用null插入,不能在insert语句中出现id

注意SqlServer的两个特有插入方法都使用了

@Options(useGeneratedKeys = true, keyProperty = "id")

这就要求表的主键为id,且为自增,如果主键不叫id可以看高级教程中的解决方法。

另外这俩方法和base中的插入方法重名,不能同时存在!

如果某种数据库和SqlServer这里类似,也可以使用这些接口(需要先测试)。

接口:InsertMapper
方法:int insert(T record);
说明:插入数据库,null值也会插入,不会使用列的默认值

接口:InsertSelectiveMapper
方法:int insertSelective(T record);
说明:插入数据库,null的属性不会保存,会使用数据库默认值

接口:SqlServerMapper
说明:这是上面两个接口的组合接口。

Ids 接口

通过操作ids字符串进行操作,ids 如 “1,2,3” 这种形式的字符串,这个方法要求实体类中有且只有一个带有@Id注解的字段,否则会抛出异常。

接口:SelectByIdsMapper
方法:List<T> selectByIds(String ids)
说明:根据主键字符串进行查询,类中只有存在一个带有@Id注解的字段

接口:DeleteByIdsMapper
方法:int deleteByIds(String ids)
说明:根据主键字符串进行删除,类中只有存在一个带有@Id注解的字段

Ids 组合接口

接口:IdsMapper<T>
方法:包含上面Ids中的前两个方法

Mapper<T> 接口

接口:Mapper<T>
该接口兼容Mapper2.x版本,继承了BaseMapper<T>ExampleMapper<T>RowBoundsMapper<T>三个组合接口。

通用Mapper的各个方法描述,参考官方的更多相关文章

  1. JavaEE高级-通用Mapper学习笔记

    通用 Mapper 笔记 1 引入 1.1作用 替我们生成常用增删改查操作的 SQL 语句. 1.2代码官方发布地址 https://gitee.com/free https://gitee.com/ ...

  2. Mybatis通用Mapper

    极其方便的使用Mybatis单表的增删改查 项目地址:http://git.oschina.net/free/Mapper 优点? 不客气的说,使用这个通用Mapper甚至能改变你对Mybatis单表 ...

  3. Mybatis通用Mapper(转)

    转自:http://blog.csdn.net/isea533/article/details/41457529 极其方便的使用Mybatis单表的增删改查 项目地址:http://git.oschi ...

  4. (二、下) springBoot 、maven 、mysql、 mybatis、 通用Mapper、lombok 简单搭建例子 《附项目源码》

    接着上篇文章中 继续前进. 一.在maven 的pom.xm中添加组件依赖, mybatis通用Mapper,及分页插件 1.mybatis通用Mapper <!-- mybatis通用Mapp ...

  5. springboot 使用mybatis 通用Mapper,pagehelper

    首先需要maven导入需要的包,这里用的是sqlserver,druid,jtds连接数据库 <dependency> <groupId>com.alibaba</gro ...

  6. 通用Mapper使用

    通用Mapper介绍 产生背景 使用Mybatis的开发者大多会因为繁多的XML映射配置而头痛不已

  7. 通用mapper的增删改查方法 留存 备忘

    Mybatis通用Mapper介绍与使用   前言 使用Mybatis的开发者,大多数都会遇到一个问题,就是要写大量的SQL在xml文件中,除了特殊的业务逻辑SQL之外,还有大量结构类似的增删改查SQ ...

  8. 浅谈Mybatis通用Mapper使用方法_java - JAVA

    文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 对单表进行增删改查是项目中不可避免的需求,Mybatis的通用Mapper插件使这些操作变得简单 添加maven依赖 在 ...

  9. Mybatis-generator/通用Mapper/Mybatis-Plus对比

    mybatis-plus-boot-starter和mybatis-spring-boot-starter冲突导致MapperScan失效问题还没有解决,只能不用mybatis-plus-boot-s ...

随机推荐

  1. XenServer 自动化布署 (关键词: PXE ANSWER SCRIPT)

    XenServer 6.x PXE自动化布署: 测试环境:win10 + Tiny pxe server 1.0.2,采用gpxelinux.0 时间:2017.1.10 PXE远程安装: 1)def ...

  2. python模块part1

    一.时间模块 1.时间表示形式 在Python中,通常有这三种方式来表示时间:时间戳.元组(struct_time).格式化的时间字符串:(1)时间戳(timestamp) :通常来说,时间戳表示的是 ...

  3. mybatis-spring和spring版本搭配问题

    所报错误:org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer 匹配的版本(my ...

  4. python之路-----前端之html协议一

    一.概述 1.1 什么是html语句? 超文本标记语言(Hypertext Markup Language,HTML)通过标签语言来标记要显示的网页中的各个部分.一套规则,浏览器认识的规则 浏览器按顺 ...

  5. Linux配置JDK、Tomcat和Mysql免安装版

    现在已有JDK.Tomcat和mysql的tar.gz压缩文件 1.解压文件 (1)解压tar.gz tar -zxvf 待解压文件名 -C 解压到目标文件目录 (2)解压zip unzip 待解压文 ...

  6. ubuntu 16.04 安装 opencv +contrib (3.2.0) + python 3.5

    环境: - ubuntu 16.04 - OpenCV + contrib 3.2.0 (文中附下载链接) - Python 3.5 基于其他环境的配置应该大同小异. 没时间解释了,直接上车. 更新下 ...

  7. 从0到1用eclipse用maven搭建web项目

    1,默认已经搭建了JDK1.5以上,以及eclipseEE版本,和maven. 2,修改maven的本地仓库和镜像,修改本地仓库是为了方便我们管理,maven的默认仓库是在C盘的USER文件夹下,我一 ...

  8. jmeter遇到问题及解决办法

    1.要得到前一个sampler的响应信息,是加beanshell sampler 还是加beanshell postprocessor?   答:在http取样器后添加beanshell sample ...

  9. Python之字典方法

    def clear(self): # 清除所有内容 """ D.clear() -> None. Remove all items from D. "&q ...

  10. 简单的bootstarp项目实例

    ===========index.html==============<!DOCTYPE html> <html> <head> <meta charset= ...