依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
配置
# mybatis-plus控制台打印SQL语句
mybatis-plus:
mapper-locations: classpath:/mapper/*.xml
configuration:
# 控制台打印执行SQL语句
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
# 扫描多层
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*Mapper.xml
新增
apiMappMapping.insert(mapping);
删除
QueryWrapper<ApiMapping> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("MAPPING_ID",dto.getId());
apiMappMapping.delete(queryWrapper);
更新
UpdateWrapper<DataSetTransformDto> dtoWrapper = new UpdateWrapper<>();
dtoWrapper.eq("ID",dto.getId());
dataSetTransformDtoMapper.update(dto,dtoWrapper);
分页
// 分页条件
Page<ApiData> page = new Page<>(current,pageSize);
// 条件构造器
QueryWrapper<ApiData> wrapper = new QueryWrapper<>();
// 不为空 like模糊查询
wrapper.like(StringUtils.isNotBlank(name),"NAME",name);
// 根据API_ID order by desc排序
wrapper.orderByDesc("API_ID");
IPage<ApiData> dataIPage = apiDataMapper.selectPage(page, wrapper);
分页嵌套另一张表集合
Page<DataSetTransformDto> page = new Page<>(current,pageSize);
QueryWrapper<DataSetTransformDto> wrapper = new QueryWrapper<>();
// wrapper.like(StringUtils.isNotBlank(name),"NAME",name);
wrapper.orderByDesc("ID");
IPage<DataSetTransformDto> dtoIPage = dataSetTransformDtoMapper.selectPage(page, wrapper);
// 遍历放入集合
dtoIPage.getRecords().stream().forEach(item->{
List<ApiMapping> mappingList = apiMappMapping.selectList(new QueryWrapper<ApiMapping>().eq("MAPPING_ID", item.getId()));
item.setApiMappingList(mappingList);
});
相关文章
暂无评论...