Giter Site home page Giter Site logo

Comments (3)

devefx avatar devefx commented on May 29, 2024

设置错误输出风格

<!-- 创建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.

fernando1987 avatar fernando1987 commented on May 29, 2024

谢谢,再请教一个问题
requestType 有没有固定格式?
以前使用hibernate validator 时,验证失败会抛出BindException由异常处理器统一处理。
这一块已经相当完善,这块可以统一处理吗?

from validator-web.

devefx avatar devefx commented on May 29, 2024

验证失败由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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.