Mapper层继承BaseMapper<T>需要引入的pom依赖方式
更新时间:2022年01月19日 11:51:44 作者:qq_43154385
这篇文章主要介绍了Mapper层继承BaseMapper<T>需要引入的pom依赖方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
Mapper层继承BaseMapper<T>引入pom依赖
<!-- mp依赖
mybatisPlus 会自动的维护Mybatis 以及MyBatis-spring相关的依赖
-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.0.3</version>
</dependency>Mybatis-Plus的BaseMapper用法
BaseMapper 用法
Mapper 继承该接口后,无需编写 mapper.xml 文件,即可获得CRUD功能
public interface BaseMapper<T> {
//插入一条记录 参数:实体 返回:int
Integer insert(T entity);
//根据 ID 删除 参数:主键ID 返回:int
Integer deleteById(Serializable id);
//根据 columnMap 条件,删除记录 参数:表字段 map 对象 返回:int
Integer deleteByMap(@Param("cm") Map<String, Object> columnMap);
//根据 entity 条件,删除记录 参数:实体对象封装操作类(可以为 null) 返回:int
Integer delete(@Param("ew") Wrapper<T> wrapper);
//删除(根据ID 批量删除) 参数:主键ID列表 返回:int
Integer deleteBatchIds(List<? extends Serializable> idList);
//根据 ID 修改 参数:实体对象 返回:int
Integer updateById(T entity);
//根据 whereEntity 条件,更新记录 参数:实体对象,实体对象封装操作类(可以为 null) 返回:int
Integer update(@Param("et") T entity, @Param("ew") Wrapper<T> wrapper);
//根据 ID 查询 参数:主键ID 返回:T
T selectById(Serializable id);
//查询(根据ID 批量查询) 参数:主键ID列表 返回:List<T>
List<T> selectBatchIds(List<? extends Serializable> idList);
//查询(根据 columnMap 条件) 参数:表字段 map 对象 返回:List<T>
List<T> selectByMap(@Param("cm") Map<String, Object> columnMap);
//根据 entity 条件,查询一条记录 参数:实体对象 返回:T
T selectOne(@Param("ew") T entity);
//根据 Wrapper 条件,查询总记录数 参数:实体对象 返回:int
Integer selectCount(@Param("ew") Wrapper<T> wrapper);
//根据 entity 条件,查询全部记录 参数:实体对象封装操作类(可以为 null) 返回:List<T>
List<T> selectList(@Param("ew") Wrapper<T> wrapper);
//根据 Wrapper 条件,查询全部记录 参数:实体对象封装操作类(可以为 null) 返回:List<T>
List<Map<String, Object>> selectMaps(@Param("ew") Wrapper<T> wrapper);
//根据 Wrapper 条件,查询全部记录 参数:实体对象封装操作类(可以为 null) 返回:List<Object>
List<Object> selectObjs(@Param("ew") Wrapper<T> wrapper);
/**
* 用法:(new RowBounds(offset, limit), ew);
* 根据 entity 条件,查询全部记录(并翻页)
* @param rowBounds
* 分页查询条件(可以为 RowBounds.DEFAULT)
* @param wrapper
* 实体对象封装操作类(可以为 null)
* @return List<T>
*/
//根据 ID 删除 参数:主键ID 返回:int
List<T> selectPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper);
/** -- 不常用,
* 根据 Wrapper 条件,查询全部记录(并翻页)
* @param rowBounds
* 分页查询条件(可以为 RowBounds.DEFAULT)
* @param wrapper
* 实体对象封装操作类
* @return List<Map<String, Object>>
*/
//根据 ID 删除 参数:主键ID 返回:int
List<Map<String, Object>> selectMapsPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper);
}用法举例
接口:
public interface UserDao extends BaseMapper<User> {
//这里面不用做任何操作
}
//具体实现方法中:
QueryWrapper<User> queryWrapper=new QueryWrapper<>();
queryWrapper.lambda().eq(User::getName,"zhangsan");
List<User> userList = UserDao.selectList(queryWrapper); //调用UserDao中的方法以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
老生常谈spring boot 1.5.4 日志管理(必看篇)
下面小编就为大家带来一篇老生常谈spring boot 1.5.4 日志管理(必看篇)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-06-06
解决springboot自定义配置Boolean属性不能生效的问题
这篇文章主要介绍了解决springboot自定义配置Boolean属性不能生效的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2024-05-05
SpringBoot使用@NotEmpty、@NotBlank、@NotNull注解进行参数校验
我们经常需要对请求参数进行校验,本文主要介绍了SpringBoot使用@NotEmpty、@NotBlank、@NotNull注解进行参数校验,具有一定的参考价值,感兴趣的可以了解一下2024-08-08
Java中==符号与equals()的使用详解(测试两个变量是否相等)
下面小编就为大家带来一篇Java中==符号与equals()的使用详解(测试两个变量是否相等)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-07-07
spring boot 使用 @Scheduled 注解和 TaskScheduler 接口实现定时任务
这篇文章主要介绍了spring boot 使用 @Scheduled 注解和 TaskScheduler 接口实现定时任务,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2023-06-06


最新评论