style: 优化全局代码格式

This commit is contained in:
2024-01-10 21:24:02 +08:00
parent ab19c05f00
commit 57c21a9109
51 changed files with 627 additions and 186 deletions

View File

@@ -55,7 +55,8 @@ public class ExcelBigNumberConverter implements Converter<Long> {
* 转换为 Java 数据(读取 Excel
*/
@Override
public Long convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
public Long convertToJavaData(ReadCellData<?> cellData,
ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
return Convert.toLong(cellData.getData());
}
@@ -64,7 +65,8 @@ public class ExcelBigNumberConverter implements Converter<Long> {
* 转换为 Excel 数据(写入 Excel
*/
@Override
public WriteCellData<Object> convertToExcelData(Long value, ExcelContentProperty contentProperty,
public WriteCellData<Object> convertToExcelData(Long value,
ExcelContentProperty contentProperty,
GlobalConfiguration globalConfiguration) {
if (null != value) {
String str = Long.toString(value);

View File

@@ -62,19 +62,25 @@ public class ExcelUtils {
* @param clazz 导出数据类型
* @param response 响应对象
*/
public static <T> void export(List<T> list, String fileName, String sheetName, Class<T> clazz,
public static <T> void export(List<T> list,
String fileName,
String sheetName,
Class<T> clazz,
HttpServletResponse response) {
try {
fileName =
String.format("%s_%s.xlsx", fileName, DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
fileName = String.format("%s_%s.xlsx", fileName, DateUtil
.format(new Date(), DatePattern.PURE_DATETIME_PATTERN));
fileName = URLUtil.encode(fileName);
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
EasyExcel.write(response.getOutputStream(), clazz).autoCloseStream(false)
// 自动适配宽度
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
// 自动转换大数值
.registerConverter(new ExcelBigNumberConverter()).sheet(sheetName).doWrite(list);
EasyExcel.write(response.getOutputStream(), clazz)
.autoCloseStream(false)
// 自动适配宽度
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
// 自动转换大数值
.registerConverter(new ExcelBigNumberConverter())
.sheet(sheetName)
.doWrite(list);
} catch (Exception e) {
log.error("Export excel occurred an error: {}. fileName: {}.", e.getMessage(), fileName, e);
throw new BaseException("导出 Excel 出现错误");