Mapper层继承BaseMapper<T>需要引入的pom依赖方式是什么,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
<!-- mp依赖
mybatisPlus 会自动的维护Mybatis 以及MyBatis-spring相关的依赖
-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.0.3</version>
</dependency>
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中的方法
看完上述内容,你们掌握Mapper层继承BaseMapper<T>需要引入的pom依赖方式是什么的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。