通用Mapper接口所封装的常用方法

  • MyMapper继承的父类
  • 首先进入MySqlMapper,查看继承的类

其中insertListMapper中包含的方法为

数据批量插入操作,主键需要自增

InsertUseGeneratedKeysMapper中包含的方法为

入表数据,主键需要自增
  • Mapper中所继承的父类

BaseMapper中的方法

方法操作
BaseSelectMapperT selectOne(T var1)根据实体类中的属性查询表数据,返回单个个体
List<T> select(T var1)根据实体类中的属性查询表数据,返回符合条件的list
List<T> selectAll();返回表中所有数据
int selectCount(T var1);返回表中符合条件的数据条数
T selectByPrimaryKey(Object var1)根据主键查询单条数据
boolean existsWithPrimaryKey(Object var1)查询主键是否存在
BaseInsertMapperint insert(T var1);插入数据,不判断属性是否为空
int insertSelective(T var1);插入数据,属性为空则不保存,使用默认值
BaseUpdateMapperint updateByPrimaryKey(T var1);更新数据,属性为空会覆盖原来的值
int updateByPrimaryKeySelective(T var1);更新数据,属性为空不会覆盖原来的值
BaseDeleteMapperint delete(T var1);根据条件删除数据库记录
int deleteByPrimaryKey(Object var1);根据主键删除数据库记录

ExampleMapper中的方法

SelectByExampleMapperList<T> selectByExample(Object var1)根据条件查询记录list
SelectOneByExampleMapperT selectOneByExample(Object var1)根据条件查询单挑记录
SelectCountByExampleMapperint selectCountByExample(Object var1);根据条件查询记录数
DeleteByExampleMapperint deleteByExample(Object var1);根据条件删除记录
UpdateByExampleMapperint updateByExample(
@Param("record") T var1,
@Param("example") Object var2)
根据条件更新,空值会覆盖原数据
UpdateByExampleSelectiveMapperint updateByExampleSelective(
@Param("record") T var1,
@Param("example") Object var2);
根据条件更新,空值会忽略

RowBoundsMapper<T>,用于分页使用,开发中可以用page-helper组件来替代

总结

通用mapper所提供的CRUD方法对单表操作,大大提高开发效率,当然复杂的多表操作还是需要在mapper.xml中自己去编写sql代码实现。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注