• <bdo id='MDcVI'></bdo><ul id='MDcVI'></ul>
    <tfoot id='MDcVI'></tfoot>

      <i id='MDcVI'><tr id='MDcVI'><dt id='MDcVI'><q id='MDcVI'><span id='MDcVI'><b id='MDcVI'><form id='MDcVI'><ins id='MDcVI'></ins><ul id='MDcVI'></ul><sub id='MDcVI'></sub></form><legend id='MDcVI'></legend><bdo id='MDcVI'><pre id='MDcVI'><center id='MDcVI'></center></pre></bdo></b><th id='MDcVI'></th></span></q></dt></tr></i><div id='MDcVI'><tfoot id='MDcVI'></tfoot><dl id='MDcVI'><fieldset id='MDcVI'></fieldset></dl></div>
      1. <legend id='MDcVI'><style id='MDcVI'><dir id='MDcVI'><q id='MDcVI'></q></dir></style></legend>

        <small id='MDcVI'></small><noframes id='MDcVI'>

        从@Valid 验证中排除一些字段

        时间:2023-09-28
      2. <i id='oEilH'><tr id='oEilH'><dt id='oEilH'><q id='oEilH'><span id='oEilH'><b id='oEilH'><form id='oEilH'><ins id='oEilH'></ins><ul id='oEilH'></ul><sub id='oEilH'></sub></form><legend id='oEilH'></legend><bdo id='oEilH'><pre id='oEilH'><center id='oEilH'></center></pre></bdo></b><th id='oEilH'></th></span></q></dt></tr></i><div id='oEilH'><tfoot id='oEilH'></tfoot><dl id='oEilH'><fieldset id='oEilH'></fieldset></dl></div>

          <tbody id='oEilH'></tbody>

            <legend id='oEilH'><style id='oEilH'><dir id='oEilH'><q id='oEilH'></q></dir></style></legend>
            1. <small id='oEilH'></small><noframes id='oEilH'>

                <bdo id='oEilH'></bdo><ul id='oEilH'></ul>
                  <tfoot id='oEilH'></tfoot>
                  本文介绍了从@Valid 验证中排除一些字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我使用 Spring 的 @Valid 注释来验证带有 javax.constraints 注释的 bean 字段.

                  I use Spring's @Valid annotation for validate bean's fields which annotated with javax.constraints annotations.

                  但是当我需要从验证中排除某些字段时(仅适用于某些情况),我遇到了一个问题.

                  But I faced a problem when I need to exclude some fields from validation (only for some cases).

                  我进行了调查,没有发现任何有用的方法,并且大多数答案的日期为 2010-2011.这是相当令人惊讶的,因为这种情况如此普遍.

                  I did an investigation didn't found any usefull ways and most of answers were dated as 2010-2011. It is quite surprisingly since this situatuion is so common.

                  Spring 4.+ 从那时起有什么变化吗?或者也许任何人都可以分享如何打败这个的个人经验?

                  Is there any changes from that times for Spring 4.+? Or maybe anyone can share personal experience how to beat this?

                  谢谢.

                  推荐答案

                  可以使用validation group,@Validated 注释.

                  You can use validation group, and @Validated annotation.

                  http://www 中有详细说明.javacodegeeks.com/2014/08/validation-groups-in-spring-mvc.html

                  该方法基于 休眠验证器组,它使您能够根据标记接口对验证进行分组并将其应用于处理程序级别,如链接中给出的示例

                  The approach is based on hibernate validator's groups and it enables you to group the validation based on the marker interface and apply it on handler level, example as given in the link

                  @RequestMapping(value = "stepTwo", method = RequestMethod.POST)
                  public String stepTwo(@Validated(Account.ValidationStepTwo.class) Account account, Errors errors) {
                    if (errors.hasErrors()) {
                        return VIEW_STEP_TWO;
                    }
                    return "redirect:summary";
                  }
                  

                  这篇关于从@Valid 验证中排除一些字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:需要一个 Hibernate 中的主键 @OneToOne 映射示例 下一篇:Spring Boot 将 Java 注释上的配置属性/消息外部化

                  相关文章

                  最新文章

                    • <bdo id='guI3P'></bdo><ul id='guI3P'></ul>
                    <legend id='guI3P'><style id='guI3P'><dir id='guI3P'><q id='guI3P'></q></dir></style></legend>

                    <small id='guI3P'></small><noframes id='guI3P'>

                    1. <tfoot id='guI3P'></tfoot>
                      <i id='guI3P'><tr id='guI3P'><dt id='guI3P'><q id='guI3P'><span id='guI3P'><b id='guI3P'><form id='guI3P'><ins id='guI3P'></ins><ul id='guI3P'></ul><sub id='guI3P'></sub></form><legend id='guI3P'></legend><bdo id='guI3P'><pre id='guI3P'><center id='guI3P'></center></pre></bdo></b><th id='guI3P'></th></span></q></dt></tr></i><div id='guI3P'><tfoot id='guI3P'></tfoot><dl id='guI3P'><fieldset id='guI3P'></fieldset></dl></div>