DateUtil.today()
时间: 2024-06-12 10:11:38 浏览: 37
根据提供的引用内容,我们可以看出这些引用都是使用了Java工具类DateUtil来处理日期时间相关的操作。而DateUtil.today()方法则是用于获取当前日期,返回值为日期类型。可以使用以下代码来实现:
Date today = DateUtil.today();
需要注意的是,该方法返回的日期只包含年月日信息,不包含具体的时分秒信息。如果需要获取当前的完整日期时间信息,可以使用DateUtil.date()方法,传入System.currentTimeMillis()或者Calendar.getInstance()作为参数。例如:
Date now = DateUtil.date(System.currentTimeMillis());
或者
Date now = DateUtil.date(Calendar.getInstance());
相关问题
解释 Boolean everyoneWriteOnce = setting.getEveryoneWriteOnce(); Boolean everyoneDayWriteOnce = setting.getEveryoneDayWriteOnce(); if (everyoneWriteOnce || everyoneDayWriteOnce) { LambdaQueryWrapper<FormData> wrapper = Wrappers.<FormData>lambdaQuery() .eq(FormData::getFormKey, formKey) .eq(FormData::getSubmitRequestIp, requestIp); if (everyoneDayWriteOnce) { wrapper.apply(StrUtil.format("date_format({},'%Y-%m-%d') = '{}'", StrUtil.toUnderlineCase(FormData.Fields.createTime), DateUtil.today())); } long writeCount = formDataService.count(wrapper); if (1 <= writeCount) { return ReturnData.error().errorMessage(setting.getWriteOncePromptText()); } } return ReturnData.success().data(setting); }
这段代码是一个判断表单提交次数的逻辑。首先获取了两个布尔类型的变量:`everyoneWriteOnce`和`everyoneDayWriteOnce`,分别表示是否开启了全局限制和每天限制。接着通过LambdaQueryWrapper构建查询条件,筛选出指定`formKey`和`requestIp`的表单数据。如果开启了每天限制,还会加入一条查询条件,确保只查询当天的表单数据。然后调用formDataService的count方法获取符合条件的表单数据数量,如果数量大于等于1,则表明用户已经提交过表单,返回错误提示信息;否则返回成功并返回当前表单设置。
XSSFWorkbook workbook = new XSSFWorkbook(); XSSFSheet sheet = workbook.createSheet(); XSSFRow headerRow = sheet.createRow(0); int columnCount = 0; for (String key : dataList.get(0).keySet()) { XSSFCell cell = headerRow.createCell(columnCount++); cell.setCellValue(SpringUtil.getBean(MetadataDictionaryService.class).getDictionaryCnName(key)); } XSSFCellStyle cellStyle = workbook.createCellStyle(); cellStyle.setAlignment(HorizontalAlignment.CENTER); int rowCount = 1; for (Map<String, Object> data : dataList) { XSSFRow dataRow = sheet.createRow(rowCount++); columnCount = 0; for (Object value : data.values()) { XSSFCell cell = dataRow.createCell(columnCount++); cell.setCellValue(value.toString()); cell.setCellStyle(cellStyle); } } for (int i = 0; i < dataList.get(0).size(); i++) { sheet.autoSizeColumn(i); } File tempFile = File.createTempFile(DateUtil.today(), ExcelTypeEnum.XLSX.getValue()); try (FileOutputStream outputStream = new FileOutputStream(tempFile)) { workbook.write(outputStream); } try (InputStream inputStream = Files.newInputStream(tempFile.toPath())) { tempFile.deleteOnExit(); FileUtil.downFile(response, filename, inputStream); } catch (Exception e) { log.error("转换流失败:{}", e); MessageException.throwMsg("转换流失败"); }我要设置自适应行宽高
您可以使用 `sheet.autoSizeColumn(columnIndex)` 和 `row.setHeightInPoints(height)` 方法来实现自适应行宽和行高。具体来说,您可以在创建 Cell 时设置样式,然后在写入文件前调用 `autoSizeColumn()` 方法设置行宽,例如:
```
// 创建样式
XSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setAlignment(HorizontalAlignment.CENTER);
// 写入数据
for (Map<String, Object> data : dataList) {
XSSFRow dataRow = sheet.createRow(rowCount++);
columnCount = 0;
for (Object value : data.values()) {
XSSFCell cell = dataRow.createCell(columnCount++);
cell.setCellValue(value.toString());
cell.setCellStyle(cellStyle);
}
}
// 自适应行宽和行高
for (int i = 0; i < dataList.get(0).size(); i++) {
sheet.autoSizeColumn(i);
}
for (int i = 0; i < rowCount; i++) {
XSSFRow row = sheet.getRow(i);
if (row != null) {
row.setHeightInPoints((float) 20.0);
}
}
```
在上面的代码中,我设置了行高为 20.0 磅,您可以根据需要进行调整。
相关推荐
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.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)
![](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)