Mapper层继承BaseMapper
发布时间:2022-01-19 13:30:06
来源:亿速云
阅读:647
作者:柒染
栏目:开发技术
Mapper层继承BaseMapper
Mapper层继承BaseMapper
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
//根据 entity 条件,删除记录 参数:实体对象封装操作类(可以为 null) 返回:int
Integer delete(@Param("ew") 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
//根据 ID 查询 参数:主键ID 返回:T
T selectById(Serializable id);
//查询(根据ID 批量查询) 参数:主键ID列表 返回:List
List
//查询(根据 columnMap 条件) 参数:表字段 map 对象 返回:List
List
//根据 entity 条件,查询一条记录 参数:实体对象 返回:T
T selectOne(@Param("ew") T entity);
//根据 Wrapper 条件,查询总记录数 参数:实体对象 返回:int
Integer selectCount(@Param("ew") Wrapper
//根据 entity 条件,查询全部记录 参数:实体对象封装操作类(可以为 null) 返回:List
List
//根据 Wrapper 条件,查询全部记录 参数:实体对象封装操作类(可以为 null) 返回:List
List
//根据 Wrapper 条件,查询全部记录 参数:实体对象封装操作类(可以为 null) 返回:List
List
/**
* 用法:(new RowBounds(offset, limit), ew);
* 根据 entity 条件,查询全部记录(并翻页)
* @param rowBounds
* 分页查询条件(可以为 RowBounds.DEFAULT)
* @param wrapper
* 实体对象封装操作类(可以为 null)
* @return List
*/
//根据 ID 删除 参数:主键ID 返回:int
List
/** -- 不常用,
* 根据 Wrapper 条件,查询全部记录(并翻页)
* @param rowBounds
* 分页查询条件(可以为 RowBounds.DEFAULT)
* @param wrapper
* 实体对象封装操作类
* @return List
*/
//根据 ID 删除 参数:主键ID 返回:int
List
}用法举例接口:
public interface UserDao extends BaseMapper
//这里面不用做任何操作
}
//具体实现方法中:
QueryWrapper
queryWrapper.lambda().eq(User::getName,"zhangsan");
List