mirror of
				https://github.com/continew-org/continew-starter.git
				synced 2025-10-30 23:00:11 +08:00 
			
		
		
		
	refactor: 优化部分代码
修复 Sonar、Codacy 扫描问题
This commit is contained in:
		| @@ -24,11 +24,11 @@ package top.charles7c.continew.starter.extension.crud.constant; | |||||||
|  */ |  */ | ||||||
| public class ContainerPool { | public class ContainerPool { | ||||||
|  |  | ||||||
|     protected ContainerPool() { |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 用户昵称 |      * 用户昵称 | ||||||
|      */ |      */ | ||||||
|     public static final String USER_NICKNAME = "UserNickname"; |     public static final String USER_NICKNAME = "UserNickname"; | ||||||
|  |  | ||||||
|  |     protected ContainerPool() { | ||||||
|  |     } | ||||||
| } | } | ||||||
| @@ -140,7 +140,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q, | |||||||
|     @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) |     @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) | ||||||
|     @ResponseBody |     @ResponseBody | ||||||
|     @PutMapping("/{id}") |     @PutMapping("/{id}") | ||||||
|     public R update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C req, @PathVariable Long id) { |     public R<Void> update(@Validated(ValidateGroup.Crud.Update.class) @RequestBody C req, @PathVariable Long id) { | ||||||
|         this.checkPermission(Api.UPDATE); |         this.checkPermission(Api.UPDATE); | ||||||
|         baseService.update(req, id); |         baseService.update(req, id); | ||||||
|         return R.ok("修改成功"); |         return R.ok("修改成功"); | ||||||
|   | |||||||
| @@ -73,7 +73,9 @@ public class GlobalErrorHandler extends BasicErrorController { | |||||||
|         } catch (IOException e) { |         } catch (IOException e) { | ||||||
|             log.error("请求地址 [{}],默认错误处理时发生 IO 异常。", path, e); |             log.error("请求地址 [{}],默认错误处理时发生 IO 异常。", path, e); | ||||||
|         } |         } | ||||||
|  |         if (log.isErrorEnabled()) { | ||||||
|             log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap)); |             log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap)); | ||||||
|  |         } | ||||||
|         return null; |         return null; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -84,7 +86,9 @@ public class GlobalErrorHandler extends BasicErrorController { | |||||||
|         HttpStatus status = super.getStatus(request); |         HttpStatus status = super.getStatus(request); | ||||||
|         R<Object> result = R.fail(status.value(), (String)errorAttributeMap.get("error")); |         R<Object> result = R.fail(status.value(), (String)errorAttributeMap.get("error")); | ||||||
|         result.setData(path); |         result.setData(path); | ||||||
|  |         if (log.isErrorEnabled()) { | ||||||
|             log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap)); |             log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap)); | ||||||
|  |         } | ||||||
|         return new ResponseEntity<>(BeanUtil.beanToMap(result), HttpStatus.OK); |         return new ResponseEntity<>(BeanUtil.beanToMap(result), HttpStatus.OK); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -29,6 +29,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties | |||||||
| import org.springframework.boot.web.servlet.FilterRegistrationBean; | import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||||||
| import org.springframework.context.annotation.Bean; | import org.springframework.context.annotation.Bean; | ||||||
| import org.springframework.context.annotation.Primary; | import org.springframework.context.annotation.Primary; | ||||||
|  | import org.springframework.core.Ordered; | ||||||
| import top.charles7c.continew.starter.core.constant.PropertiesConstants; | import top.charles7c.continew.starter.core.constant.PropertiesConstants; | ||||||
| import top.charles7c.continew.starter.core.constant.StringConstants; | import top.charles7c.continew.starter.core.constant.StringConstants; | ||||||
|  |  | ||||||
| @@ -73,7 +74,7 @@ public class TraceAutoConfiguration { | |||||||
|         FilterRegistrationBean<TLogServletFilter> registration = new FilterRegistrationBean<>(); |         FilterRegistrationBean<TLogServletFilter> registration = new FilterRegistrationBean<>(); | ||||||
|         registration.setFilter(new TLogServletFilter(traceProperties)); |         registration.setFilter(new TLogServletFilter(traceProperties)); | ||||||
|         registration.addUrlPatterns(StringConstants.PATH_PATTERN_CURRENT_DIR); |         registration.addUrlPatterns(StringConstants.PATH_PATTERN_CURRENT_DIR); | ||||||
|         registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); |         registration.setOrder(Ordered.HIGHEST_PRECEDENCE); | ||||||
|         return registration; |         return registration; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -64,11 +64,9 @@ public class FileUploadUtils { | |||||||
|             String pathname = filePath + fileName; |             String pathname = filePath + fileName; | ||||||
|             File dest = new File(pathname).getCanonicalFile(); |             File dest = new File(pathname).getCanonicalFile(); | ||||||
|             // 如果父路径不存在,自动创建 |             // 如果父路径不存在,自动创建 | ||||||
|             if (!dest.getParentFile().exists()) { |             if (!dest.getParentFile().exists() && (!dest.getParentFile().mkdirs())) { | ||||||
|                 if (!dest.getParentFile().mkdirs()) { |  | ||||||
|                 log.error("Create upload file parent path failed."); |                 log.error("Create upload file parent path failed."); | ||||||
|             } |             } | ||||||
|             } |  | ||||||
|             // 文件写入 |             // 文件写入 | ||||||
|             multipartFile.transferTo(dest); |             multipartFile.transferTo(dest); | ||||||
|             return dest; |             return dest; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user