LambdaQueryWrapperX<CpuInformationDO> queryWrapper = new LambdaQueryWrapperX<>();中and用法
时间: 2023-11-07 14:03:08 浏览: 134
在LambdaQueryWrapper中,可以使用and方法来添加一个AND条件。例如,您可以使用以下代码来创建一个包含两个AND条件的查询构造器:
LambdaQueryWrapperX<CpuInformationDO> queryWrapper = new LambdaQueryWrapperX<>();
queryWrapper.eq("column1", value1)
.and(wrapper -> wrapper.eq("column2", value2));
这将创建一个查询构造器,其中column1等于value1,并且column2等于value2。
相关问题
LambdaQueryWrapperX<ScanDO> 可以模糊查询吗
可以使用 LambdaQueryWrapper 的 like 方法进行模糊查询。例如:
```java
LambdaQueryWrapper<ScanDO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(ScanDO::getName, "关键字");
List<ScanDO> result = scanMapper.selectList(queryWrapper);
```
这样就可以通过 `ScanDO` 实体类中的 `name` 字段进行模糊查询,关键字为 "关键字"。
ProjectHistory projectHistory = projectHistoryService.getById(projectHistoryId); Unit unit = unitService.getById(projectHistory.getPricingUnitId()); List<ProjectCalculateResult> projectCalculateResultList = projectCalculateResultService.list(new LambdaQueryWrapperX<ProjectCalculateResult>().eq(ProjectCalculateResult::getProjectHistoryId, projectHistoryId)); //计算总数量 insideTaskService.statisticalOptions(projectCalculateResultList); String unitName = unit.getUnitName(); unitName = unitName.substring(0, 2); String projectName = projectHistory.getProjectName(); Map<String, Object> params = new HashMap<>(); ClassPathResource resource = new ClassPathResource("templates"+File.separator+"project_letters.docx"); InputStream inputStream = resource.getInputStream(); MyXWPFDocument doc = new MyXWPFDocument(inputStream); //简单渲染文本 params.put("projectName",projectName); params.put("unit",unitName); //渲染表格 List<Map<String, Object>> jobs = new ArrayList<>(); Map<String, Object> job; for (int i = 0; i < projectCalculateResultList.size(); i++) { job = new HashMap<>(); job.put("id", i+1); job.put("zxbz",projectCalculateResultList.get(i).getDecoration()); job.put("jsjd",projectCalculateResultList.get(i).getFamilyProperty()); BigDecimal projectRent = projectCalculateResultList.get(i).getProjectRent().setScale(2, BigDecimal.ROUND_HALF_UP); job.put("projectRent",projectRent); jobs.add(job); } params.put("jobs",jobs); SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy年MM月dd日"); String transformDate=simpleDateFormat.format(new Date()); params.put("dateTime",transformDate); String temDir="templates"+ File.separator+"project_letters.docx"; ;//生成临时文件存放地址 //生成文件名 Long time = new Date().getTime(); // 生成的word格式 String formatSuffix = ".docx"; // 拼接后的文件名 String fileName = time + formatSuffix;//文件名 带后缀 //导出word WordUtils.exportWordDoc(doc, temDir, fileName, params, request, response);怎么改才能将下载的文件字体为仿宋
要将下载的文件字体设置为仿宋,你需要在导出Word文档之前,将文档中的字体样式修改为仿宋。可以参考以下代码:
```java
// 渲染表格
List<Map<String, Object>> jobs = new ArrayList<>();
Map<String, Object> job;
for (int i = 0; i < projectCalculateResultList.size(); i++) {
job = new HashMap<>();
job.put("id", i+1);
job.put("zxbz", projectCalculateResultList.get(i).getDecoration());
job.put("jsjd", projectCalculateResultList.get(i).getFamilyProperty());
BigDecimal projectRent = projectCalculateResultList.get(i).getProjectRent().setScale(2, BigDecimal.ROUND_HALF_UP);
job.put("projectRent", projectRent);
// 设置字体为仿宋
XWPFRun run = (XWPFRun)job.get("projectRent");
run.setFontFamily("仿宋");
jobs.add(job);
}
params.put("jobs", jobs);
// 导出word
WordUtils.exportWordDoc(doc, temDir, fileName, params, request, response);
```
在上述代码中,我添加了一行代码来设置表格中"projectRent"字段的字体为仿宋。请确保系统中存在仿宋字体。这样,在导出的Word文档中,"projectRent"字段的字体将被设置为仿宋。
阅读全文