Comments (3)
设置错误输出风格
<!-- 创建Validator配置 -->
<bean id="validatorConfig" class="org.devefx.validator.ValidatorConfig">
<property name="invalidHandler">
<bean class="org.devefx.validator.internal.engine.DefaultInvalidHandler">
<!-- 设置输出风格为JSON -->
<property name="outputStyle" value="JSON"/>
</bean>
</property>
</bean>
支持post数据为xml/json类型
- 必须指定requestType(请求的类型)
- 请求的Header中必须设置Content-Type(默认提供application/xml与application/json)
如果Content-Type为application/xml,请提交json数据
更多自定义类型去参考HttpMessageReader.java
@Valid(value=MyValidation.class, requestType=MyModel.class)
@RequestMapping("/")
public void render() {
// 验证通过后,获取请求模型
MyModel myModel = (MyModel) ThreadContext.getModel();
}
from validator-web.
谢谢,再请教一个问题
requestType 有没有固定格式?
以前使用hibernate validator 时,验证失败会抛出BindException由异常处理器统一处理。
这一块已经相当完善,这块可以统一处理吗?
from validator-web.
验证失败由InvalidHandler处理,ValidatorConfig.setInvalidHandler设置统一处理器,也可以在具体的Validation使用ValidationContext.setInvalidHandler进行特殊处理
请参考配置:https://github.com/devefx/validator-web/blob/master/docs/springmvc/getting-started.md
from validator-web.
Related Issues (4)
- 大神,有没有文档以供学习?
- 大神,错误消息国际化和业务校验Xml化的建议 HOT 1
- 有没有 基于注解的配置 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from validator-web.