乐趣区

关于java:MybatisPlus用法

依赖

<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);
        });
退出移动版