mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 08:57:17 +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 {
|
||||
|
||||
protected ContainerPool() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
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)
|
||||
@ResponseBody
|
||||
@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);
|
||||
baseService.update(req, id);
|
||||
return R.ok("修改成功");
|
||||
|
@@ -73,7 +73,9 @@ public class GlobalErrorHandler extends BasicErrorController {
|
||||
} catch (IOException e) {
|
||||
log.error("请求地址 [{}],默认错误处理时发生 IO 异常。", path, e);
|
||||
}
|
||||
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
|
||||
if (log.isErrorEnabled()) {
|
||||
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -84,7 +86,9 @@ public class GlobalErrorHandler extends BasicErrorController {
|
||||
HttpStatus status = super.getStatus(request);
|
||||
R<Object> result = R.fail(status.value(), (String)errorAttributeMap.get("error"));
|
||||
result.setData(path);
|
||||
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
|
||||
if (log.isErrorEnabled()) {
|
||||
log.error("请求地址 [{}],发生错误,错误信息:{}。", path, JSONUtil.toJsonStr(errorAttributeMap));
|
||||
}
|
||||
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.context.annotation.Bean;
|
||||
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.StringConstants;
|
||||
|
||||
@@ -73,7 +74,7 @@ public class TraceAutoConfiguration {
|
||||
FilterRegistrationBean<TLogServletFilter> registration = new FilterRegistrationBean<>();
|
||||
registration.setFilter(new TLogServletFilter(traceProperties));
|
||||
registration.addUrlPatterns(StringConstants.PATH_PATTERN_CURRENT_DIR);
|
||||
registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE);
|
||||
registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||
return registration;
|
||||
}
|
||||
|
||||
|
@@ -64,10 +64,8 @@ public class FileUploadUtils {
|
||||
String pathname = filePath + fileName;
|
||||
File dest = new File(pathname).getCanonicalFile();
|
||||
// 如果父路径不存在,自动创建
|
||||
if (!dest.getParentFile().exists()) {
|
||||
if (!dest.getParentFile().mkdirs()) {
|
||||
log.error("Create upload file parent path failed.");
|
||||
}
|
||||
if (!dest.getParentFile().exists() && (!dest.getParentFile().mkdirs())) {
|
||||
log.error("Create upload file parent path failed.");
|
||||
}
|
||||
// 文件写入
|
||||
multipartFile.transferTo(dest);
|
||||
|
Reference in New Issue
Block a user