Commit d852e7bf by xmh

全局异常处理和同名判断

1 parent bebbb0fd
package com.viontech.storage.config;
import com.viontech.storage.entity.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import java.util.Optional;
/**
* .
*
* @author 谢明辉
* @date 2020/6/4
*/
@RestControllerAdvice
public class GlobalExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
@ExceptionHandler(Exception.class)
public Object exceptionHandler(Exception e, HttpServletRequest request) {
log.error(request.getRequestURI() + "?" + Optional.ofNullable(request.getQueryString()).orElse(""), e);
return Message.error(e.getMessage());
}
}
...@@ -76,6 +76,11 @@ public class StorageConfigController { ...@@ -76,6 +76,11 @@ public class StorageConfigController {
@PostMapping @PostMapping
public Message<StorageConfig> add(@RequestBody StorageConfigVo storageConfigVo) { public Message<StorageConfig> add(@RequestBody StorageConfigVo storageConfigVo) {
Assert.notNull(storageConfigVo.getName(), "name不能为空");
Long count = storageConfigService.lambdaQuery().eq(StorageConfig::getName, storageConfigVo.getName())
.count();
Assert.isTrue(count == 0, "已存在同名存储配置");
List<Context> contexts = storageConfigVo.getContexts(); List<Context> contexts = storageConfigVo.getContexts();
if (CollectionUtil.isNotEmpty(contexts)) { if (CollectionUtil.isNotEmpty(contexts)) {
for (Context item : contexts) { for (Context item : contexts) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!