List<TVehcertUploadLog> list = tVehcertUploadLogService.list(new LambdaQueryWrapper<TVehcertUploadLog>().eq(StringUtils.isNotBlank(tVehcertUploadLog.getVin()),TVehcertUploadLog::getVin,tVehcertUploadLog.getVin())连表查询T_DLLX不适用.leftjoin
时间: 2024-02-01 20:16:43 浏览: 33
如果要进行连表查询T_DLLX,可以使用以下方式:
```
List<TVehcertUploadLog> list = tVehcertUploadLogService.list(new LambdaQueryWrapper<TVehcertUploadLog>()
.eq(StringUtils.isNotBlank(tVehcertUploadLog.getVin()), TVehcertUploadLog::getVin, tVehcertUploadLog.getVin())
.leftJoin(T_DLLX.class, TVehcertUploadLog::getDlbh, T_DLLX::getDlbh)
.list());
```
这里使用了 `leftJoin` 进行左连接查询,并在参数中指定了两个实体类之间的关联关系。需要根据实际情况做出修改。
相关问题
public List<Document> listDocument(PageInfo<?> pageInfo, Document document) { PageHelper.startPage(pageInfo.getCurrent(), pageInfo.getPageSize()); List<Document> documentList = documentMapper.selectList(Wrappers.<Document>lambdaQuery() .like(StringUtils.isNotBlank(document.getTitle()), Document::getTitle, document.getTitle()) .like(StringUtils.isNotBlank(document.getSummary()), Document::getSummary, document.getSummary()) .eq(document.getCateId() != null, Document::getCateId, document.getCateId()) .eq(document.getDeptId() != null, Document::getDeptId, document.getDeptId()) .eq(document.getActive() != null, Document::getActive, document.getActive()) .eq(document.getRecommend() != null, Document::getRecommend, document.getRecommend()) .eq(document.getCarousel() != null, Document::getCarousel, document.getCarousel()) .orderByDesc(Document::getDateTime) ); if (!documentList.isEmpty()) { List<Long> documentIdList = documentList.stream().map(Document::getCateId).collect(Collectors.toList()); Map<Long, Cate> cateMap = cateMapper.selectBatchIds(documentIdList).stream().collect(Collectors.toMap(Cate::getId, e -> e, (e1, e2) -> e2)); for (Document documentItem : documentList) { documentItem.setCate(cateMap.get(documentItem.getCateId())); } } return documentList; }
这段代码是一个用于根据条件查询文档列表的方法。方法的参数包括一个 PageInfo 对象和一个 Document 对象。PageInfo 是用于分页查询的工具类,包含当前页码和页面大小等信息。Document 是文档的实体类。
在方法内部,首先使用 PageHelper.startPage() 方法设置分页参数。然后使用 documentMapper.selectList() 方法进行查询,查询条件使用了 Wrappers.<Document>lambdaQuery() 来构建。
在 lambdaQuery() 内部,根据传入的 document 对象的属性值来构建查询条件。使用 StringUtils.isNotBlank() 判断属性值是否为空,如果不为空,则使用 like() 方法进行模糊匹配,如果为空则不添加该条件。使用 eq() 方法进行相等匹配。
最后,通过 orderByDesc() 方法按照文档的日期时间进行降序排序。
如果查询结果不为空,则通过 documentList.stream().map().collect(Collectors.toList()) 获取文档列表中的所有文档分类ID,并使用 cateMapper.selectBatchIds() 批量查询对应的文档分类信息。
然后,通过遍历文档列表,并通过 cateMap.get() 方法设置每个文档的分类信息。
最后,返回查询结果 documentList。
优化 这段代码 LambdaQueryWrapper<AuthRoleInfo> userTestWrapper = Wrappers.<AuthRoleInfo>lambdaQuery() .orderByAsc(AuthRoleInfo::getRoleId); userTestWrapper.eq(AuthRoleInfo::getLogIcdel,"0"); if(!StringUtils.isBlank(roleManagerSearch.getRoleName())){ userTestWrapper.like(AuthRoleInfo::getRoleName,roleManagerSearch.getRoleName()); } if(!StringUtils.isBlank(roleManagerSearch.getRoleCode())){ userTestWrapper.like(AuthRoleInfo::getRoleCode,roleManagerSearch.getRoleCode()); } Page<Object> objects = PageHelper.startPage(roleManagerSearch.getPage(), roleManagerSearch.getPageSize()); List<AuthRoleInfo> roleManagerList = roleManagerMapper.selectList(userTestWrapper);
这段代码可以进行一些优化,例如可以将 lambdaQuery() 方法的返回值存储在一个变量中,避免多次调用该方法;可以使用 StringUtils 的 isNotBlank() 方法代替 !StringUtils.isBlank();可以使用 lambda 表达式的 and() 方法将多个条件连接起来,避免多次调用 eq() 和 like() 方法。另外,可以考虑使用 MyBatis-Plus 提供的分页插件来实现分页查询,避免使用 PageHelper。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)