MybatisPlus生成器ServiceImpl类详解( 二 )

ServiceImpl类各方法(未过期)的作用1.getBaseMapper()
2.getEntityClass()
3.saveBatch()
4.saveOrUpdate()
5.saveOrUpdateBatch()
6.updateBatchById()
7.getOne()
8.getMap()
9.getObj()
ServiceImpl类各属性的作用1.log:打印日志
2.baseMapper:实现了许多的SQL操作
3.entityClass:实体类
4.mapperClass:映射类
BaseMapper类中各方法ServiceImpl类中有这个类的成员变量,因此通过ServiceImpl这个类便能够操作如下方法:
1.int insert(T entity);:插入记录
2.int deleteById(Serializable id);:通过id删除指定记录
3.int deleteByMap(Map<String, Object> columnMap):通过Map集合添加删除指定记录
4.int delete(@Param(Constants.WRAPPER) Wrapper queryWrapper):通过添加构造器删除指定记录
5.int deleteBatchIds(Collection<? extends Serializable> idList):通过List集合批量删除记录
【MybatisPlus生成器ServiceImpl类详解】
6.int updateById(T entity):根据id修改指定记录
7.int update(T entity, Wrapper updateWrapper):根据条件构造器
8.T selectById(Serializable id):根据id查询指定记录
9.List selectBatchIds(Collection<? extends Serializable> idList):根据List集合批量查询记录
10.List selectByMap(Map<String, Object> columnMap):根据Map集合查询记录
11.T selectOne(Wrapper queryWrapper):根据条件构造器查询一条记录
12.Integer selectCount(Wrapper queryWrapper):根据条件构造器查询记录总数
13.List selectList(Wrapper queryWrapper):根据条件构造器查询全部记录
14.List<Map<String, Object>> selectMaps(Wrapper queryWrapper):根据条件构造器查询全部记录
15.ist selectObjs(Wrapper queryWrapper):根据条件构造器查询全部记录
16.<E extends IPage> E selectPage(E page, Wrapper queryWrapper):根据条件构造器查询全部记录(并翻页)
17.<E extends IPage<Map<String, Object>>> E selectMapsPage(E page, Wrapper queryWrapper):根据条件构造器查询全部记录(并翻页)
Wrapper类各方法1.getEntity():实体对象(子类实现)
2.getSqlSelectgetSqlSet():
3.getSqlComment():
4.getSqlFirst():
5.getExpression():获取 MergeSegments
6.getCustomSqlSegment():获取自定义SQL 简化自定义XML复杂情况
7.isEmptyOfWhere():查询条件为空(包含entity)
8.nonEmptyOfWhere():查询条件不为空(包含entity)
9.isEmptyOfNormal():查询条件为空(不包含entity)
10.nonEmptyOfNormal():查询条件为空(不包含entity)
11.nonEmptyOfEntity():深层实体判断属性
12.fieldStrategyMatch():根据实体FieldStrategy属性来决定判断逻辑
13.isEmptyOfEntity():深层实体判断属性
14.getTargetSql():获取格式化后的执行sql
15.clear():条件清空
实例说明
public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {}public class CategoryServiceImpl extends ServiceImpl<CategoryDao, CategoryEntity> implements CategoryService {}在ServiceImpl中已经注入了Mapper对象: protected M baseMapper;因此XXXServiceImpl只要继承了这个原生的ServiceImpl,这个M实体Dao就已经注入了进来,不需要重新注入 。




推荐阅读