千家信息网

Mapper层继承BaseMapper<T>需要引入的pom依赖方式是什么

发表于:2024-10-25 作者:千家信息网编辑
千家信息网最后更新 2024年10月25日,Mapper层继承BaseMapper需要引入的pom依赖方式是什么,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。Mapper层继承Ba
千家信息网最后更新 2024年10月25日Mapper层继承BaseMapper<T>需要引入的pom依赖方式是什么

Mapper层继承BaseMapper需要引入的pom依赖方式是什么,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

Mapper层继承BaseMapper引入pom依赖

                    com.baomidou            mybatis-plus            3.0.3        

Mybatis-Plus的BaseMapper用法

BaseMapper 用法

Mapper 继承该接口后,无需编写 mapper.xml 文件,即可获得CRUD功能

public interface BaseMapper {    //插入一条记录  参数:实体  返回:int    Integer insert(T entity);     //根据 ID 删除  参数:主键ID  返回:int    Integer deleteById(Serializable id);         //根据 columnMap 条件,删除记录  参数:表字段 map 对象  返回:int    Integer deleteByMap(@Param("cm") Map columnMap);      //根据 entity 条件,删除记录  参数:实体对象封装操作类(可以为 null)  返回:int    Integer delete(@Param("ew") Wrapper wrapper);      //删除(根据ID 批量删除)  参数:主键ID列表  返回:int    Integer deleteBatchIds(List idList);      //根据 ID 修改  参数:实体对象  返回:int    Integer updateById(T entity);      //根据 whereEntity 条件,更新记录  参数:实体对象,实体对象封装操作类(可以为 null) 返回:int    Integer update(@Param("et") T entity, @Param("ew") Wrapper wrapper);      //根据 ID 查询  参数:主键ID  返回:T    T selectById(Serializable id);      //查询(根据ID 批量查询)  参数:主键ID列表  返回:List    List selectBatchIds(List idList);      //查询(根据 columnMap 条件)  参数:表字段 map 对象  返回:List    List selectByMap(@Param("cm") Map columnMap);      //根据 entity 条件,查询一条记录  参数:实体对象  返回:T    T selectOne(@Param("ew") T entity);     //根据 Wrapper 条件,查询总记录数  参数:实体对象  返回:int    Integer selectCount(@Param("ew") Wrapper wrapper);      //根据 entity 条件,查询全部记录  参数:实体对象封装操作类(可以为 null)  返回:List    List selectList(@Param("ew") Wrapper wrapper);      //根据 Wrapper 条件,查询全部记录  参数:实体对象封装操作类(可以为 null) 返回:List    List> selectMaps(@Param("ew") Wrapper wrapper);      //根据 Wrapper 条件,查询全部记录  参数:实体对象封装操作类(可以为 null)  返回:List    List selectObjs(@Param("ew") Wrapper wrapper);     /**      * 用法:(new RowBounds(offset, limit), ew);     * 根据 entity 条件,查询全部记录(并翻页)     * @param rowBounds     * 分页查询条件(可以为 RowBounds.DEFAULT)     * @param wrapper     * 实体对象封装操作类(可以为 null)     * @return List     */     //根据 ID 删除  参数:主键ID  返回:int    List selectPage(RowBounds rowBounds, @Param("ew") Wrapper wrapper);     /** -- 不常用,     * 根据 Wrapper 条件,查询全部记录(并翻页)     * @param rowBounds     * 分页查询条件(可以为 RowBounds.DEFAULT)     * @param wrapper     * 实体对象封装操作类     * @return List>     */     //根据 ID 删除  参数:主键ID  返回:int    List> selectMapsPage(RowBounds rowBounds, @Param("ew") Wrapper wrapper);}

用法举例

接口:

public interface UserDao extends BaseMapper {    //这里面不用做任何操作}//具体实现方法中:QueryWrapper queryWrapper=new QueryWrapper<>();queryWrapper.lambda().eq(User::getName,"zhangsan");List userList = UserDao.selectList(queryWrapper); //调用UserDao中的方法

看完上述内容,你们掌握Mapper层继承BaseMapper需要引入的pom依赖方式是什么的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!

0