新增自定义数据校验

This commit is contained in:
RuoYi
2019-07-19 09:53:45 +08:00
parent 3fc965e0e7
commit bf6c66a77b
24 changed files with 214 additions and 42 deletions

View File

@ -1,11 +1,15 @@
package com.ruoyi.framework.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import com.ruoyi.common.config.Global;
import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
/**
* 通用配置
@ -21,6 +25,9 @@ public class ResourcesConfig implements WebMvcConfigurer
@Value("${shiro.user.indexUrl}")
private String indexUrl;
@Autowired
private RepeatSubmitInterceptor repeatSubmitInterceptor;
/**
* 默认首页的设置,当输入域名是可以自动跳转到默认指定的网页
*/
@ -40,4 +47,13 @@ public class ResourcesConfig implements WebMvcConfigurer
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
/**
* 自定义拦截规则
*/
@Override
public void addInterceptors(InterceptorRegistry registry)
{
registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**");
}
}

View File

@ -4,6 +4,7 @@ import javax.servlet.http.HttpServletRequest;
import org.apache.shiro.authz.AuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@ -93,6 +94,17 @@ public class GlobalExceptionHandler
}
}
/**
* 自定义验证异常
*/
@ExceptionHandler(BindException.class)
public AjaxResult validatedBindException(BindException e)
{
log.error(e.getMessage(), e);
String message = e.getAllErrors().get(0).getDefaultMessage();
return AjaxResult.error(message);
}
/**
* 演示模式异常
*/