refactor: 优化插件模块注释规范
- 移除脱敏、Excel、结果处理、Sa-Token等插件的行尾注释 - 改为独立行注释格式 - 修复ResultResponseHandler的扫包配置 - 统一插件模块代码风格
This commit is contained in:
parent
a7e9e0cf1d
commit
b87583bb67
@ -5,8 +5,10 @@ import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Target({ElementType.TYPE}) // 可用在字段上。
|
||||
@Retention(RetentionPolicy.RUNTIME) // 运行时生效。
|
||||
// 可用在字段上。
|
||||
@Target({ElementType.TYPE})
|
||||
// 运行时生效。
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
@Import({ DesensitizeJsonSerializer.class })
|
||||
|
||||
@ -88,7 +88,8 @@ public class BigDataEasyExcelUtil {
|
||||
long exportStartTime = System.currentTimeMillis();
|
||||
log.info("报表导出Size: " + data.size() + "条。");
|
||||
|
||||
List<List<T>> lists = SplitList.splitList(data, MAXROWS); // 分割的集合
|
||||
// 分割的集合
|
||||
List<List<T>> lists = SplitList.splitList(data, MAXROWS);
|
||||
|
||||
OutputStream out = getOutputStream(fileName, response);
|
||||
ExcelWriterBuilder excelWriterBuilder = EasyExcel.write(out, clazz).excelType(ExcelTypeEnum.XLSX);
|
||||
@ -110,8 +111,10 @@ public class BigDataEasyExcelUtil {
|
||||
|
||||
public static OutputStream getOutputStream(String fileName, HttpServletResponse response) throws Exception {
|
||||
fileName = URLEncoder.encode(fileName, "UTF-8");
|
||||
// response.setContentType("application/vnd.ms-excel"); // .xls
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); // .xlsx
|
||||
// .xls
|
||||
// response.setContentType("application/vnd.ms-excel");
|
||||
// .xlsx
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||
return response.getOutputStream();
|
||||
|
||||
@ -45,7 +45,8 @@ public class SplitList {
|
||||
List<List<T>> result = new ArrayList<List<T>>();
|
||||
int number = source.size() / n;
|
||||
int remaider = source.size() % n;
|
||||
int offset = 0; // 偏移量,每有一个余数分配,就要往右偏移一位
|
||||
// 偏移量,每有一个余数分配,就要往右偏移一位
|
||||
int offset = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
List<T> list1 = null;
|
||||
if (remaider > 0) {
|
||||
|
||||
@ -18,6 +18,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author leocoder
|
||||
* @description 全局统一返回类
|
||||
* bug: (basePackages = "org.leocoder")建议扫包
|
||||
* 为什么?
|
||||
@ -27,7 +28,7 @@ import java.lang.reflect.Method;
|
||||
* 就会造成Swagger失效。
|
||||
* 解决knife4j失效问题:(basePackages = { "org.leocoder" }, annotations = { RestController.class })
|
||||
*/
|
||||
@RestControllerAdvice(basePackages = { "com" }, annotations = { RestController.class })
|
||||
@RestControllerAdvice(basePackages = { "org.leocoder" }, annotations = { RestController.class })
|
||||
public class ResultResponseHandler implements ResponseBodyAdvice<Object> {
|
||||
|
||||
/**
|
||||
@ -38,17 +39,17 @@ public class ResultResponseHandler implements ResponseBodyAdvice<Object> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* 参数body 代表其实就是SpringMvc的请求的方法的结果 */
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, @Nullable MethodParameter methodParameter, @Nullable MediaType mediaType, Class<? extends HttpMessageConverter<?>> coderClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
|
||||
/* 对请求的结果在这里统一返回和处理 */
|
||||
// 参数body 代表其实就是SpringMvc的请求的方法的结果
|
||||
// 对请求的结果在这里统一返回和处理
|
||||
|
||||
if (body instanceof ErrorHandler errorHandler) {
|
||||
// 1、如果返回的结果是一个异常的结果,就把异常返回的结构数据倒腾到R.error里面即可
|
||||
// 如果返回的结果是一个异常的结果,就把异常返回的结构数据倒腾到R.error里面即可
|
||||
return ResultUtils.error(errorHandler.getStatus(), errorHandler.getMsg());
|
||||
}
|
||||
|
||||
// 2、检查是否有 CoderIgnoreR 注解,如果有则不进行封装,直接返回原始数据body
|
||||
// 检查是否有 CoderIgnoreR 注解,如果有则不进行封装,直接返回原始数据body
|
||||
if (methodParameter != null) {
|
||||
Method method = methodParameter.getMethod();
|
||||
Class<?> declaringClass = method.getDeclaringClass();
|
||||
@ -70,7 +71,7 @@ public class ResultResponseHandler implements ResponseBodyAdvice<Object> {
|
||||
|
||||
if (body instanceof String) {
|
||||
try {
|
||||
// 3、因为SpringMVC数据转换器对String是有特殊处理 StringHttpMessageConverter,解决String类型的返回
|
||||
// 因为SpringMVC数据转换器对String是有特殊处理 StringHttpMessageConverter,解决String类型的返回
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
R r = R.success(body);
|
||||
return objectMapper.writeValueAsString(r);
|
||||
@ -79,7 +80,7 @@ public class ResultResponseHandler implements ResponseBodyAdvice<Object> {
|
||||
}
|
||||
}
|
||||
|
||||
// 4、对于其他类型的对象,直接封装到 R 中
|
||||
// 对于其他类型的对象,直接封装到 R 中
|
||||
return R.success(body);
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,8 @@ import java.util.Set;
|
||||
*/
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@Component // 保证此类被SpringBoot扫描,完成Sa-Token的自定义权限验证扩展
|
||||
// 保证此类被SpringBoot扫描,完成Sa-Token的自定义权限验证扩展
|
||||
@Component
|
||||
public class CoderSaTokenStpInterfaceImpl implements StpInterface {
|
||||
|
||||
private final SaRoleService saRoleService;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user