Skip to content

Commit

Permalink
refactor: 优化部分代码
Browse files Browse the repository at this point in the history
修复 Sonar、Codacy 扫描问题
  • Loading branch information
Charles7c committed Feb 2, 2024
1 parent 4558cf0 commit 711bbe2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
*/
public class ContainerPool {

protected ContainerPool() {
}

/**
* 用户昵称
*/
public static final String USER_NICKNAME = "UserNickname";

protected ContainerPool() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public R<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req)
@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("修改成功");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public ModelAndView errorHtml(HttpServletRequest request, HttpServletResponse re
} 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;
}

Expand All @@ -84,7 +86,9 @@ public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;

Expand Down Expand Up @@ -73,7 +74,7 @@ public FilterRegistrationBean<TLogServletFilter> filterRegistration() {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,8 @@ public static File upload(MultipartFile multipartFile, String filePath, boolean
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);
Expand Down

0 comments on commit 711bbe2

Please sign in to comment.