久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <small id='vsf4j'></small><noframes id='vsf4j'>

      <bdo id='vsf4j'></bdo><ul id='vsf4j'></ul>
  2. <i id='vsf4j'><tr id='vsf4j'><dt id='vsf4j'><q id='vsf4j'><span id='vsf4j'><b id='vsf4j'><form id='vsf4j'><ins id='vsf4j'></ins><ul id='vsf4j'></ul><sub id='vsf4j'></sub></form><legend id='vsf4j'></legend><bdo id='vsf4j'><pre id='vsf4j'><center id='vsf4j'></center></pre></bdo></b><th id='vsf4j'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vsf4j'><tfoot id='vsf4j'></tfoot><dl id='vsf4j'><fieldset id='vsf4j'></fieldset></dl></div>

    1. <tfoot id='vsf4j'></tfoot>
      <legend id='vsf4j'><style id='vsf4j'><dir id='vsf4j'><q id='vsf4j'></q></dir></style></legend>

      javax.validation.constraints 中的注釋不起作用

      Annotations from javax.validation.constraints not working(javax.validation.constraints 中的注釋不起作用)
        <i id='lKBie'><tr id='lKBie'><dt id='lKBie'><q id='lKBie'><span id='lKBie'><b id='lKBie'><form id='lKBie'><ins id='lKBie'></ins><ul id='lKBie'></ul><sub id='lKBie'></sub></form><legend id='lKBie'></legend><bdo id='lKBie'><pre id='lKBie'><center id='lKBie'></center></pre></bdo></b><th id='lKBie'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lKBie'><tfoot id='lKBie'></tfoot><dl id='lKBie'><fieldset id='lKBie'></fieldset></dl></div>
        • <bdo id='lKBie'></bdo><ul id='lKBie'></ul>

          <legend id='lKBie'><style id='lKBie'><dir id='lKBie'><q id='lKBie'></q></dir></style></legend>

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

              <tbody id='lKBie'></tbody>
                <tfoot id='lKBie'></tfoot>
                本文介紹了javax.validation.constraints 中的注釋不起作用的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                使用 javax.validation.constraints 中的注解(如 @Size@NotNull 等)需要什么配置?這是我的代碼:

                What configuration is needed to use annotations from javax.validation.constraints like @Size, @NotNull, etc.? Here's my code:

                import javax.validation.constraints.NotNull;
                import javax.validation.constraints.Size;
                
                public class Person {
                      @NotNull
                      private String id;
                
                      @Size(max = 3)
                      private String name;
                
                      private int age;
                
                      public Person(String id, String name, int age) {
                        this.id = id;
                        this.name = name;
                        this.age = age;
                      }
                }
                

                當我嘗試在另一個類中使用它時,驗證不起作用(即對象創建時沒有錯誤):

                When I try to use it in another class, validation doesn't work (i.e. the object is created without error):

                Person P = new Person(null, "Richard3", 8229));
                

                為什么這不對 idname 應用約束?我還需要做什么?

                Why doesn't this apply constraints for id and name? What else do I need to do?

                推薦答案

                要讓 JSR-303 bean 驗證在 Spring 中工作,您需要做幾件事:

                For JSR-303 bean validation to work in Spring, you need several things:

                1. 注解的MVC命名空間配置:<mvc:annotation-driven/>
                2. JSR-303 規范 JAR:validation-api-1.0.0.GA.jar(看起來你已經有了)
                3. 規范的實現,例如 Hibernate Validation,這似乎是最常用的示例:hibernate-validator-4.1.0.Final.jar
                4. 在要驗證的 bean 中,驗證注釋,來自規范 JAR 或來自實現 JAR(您已經完成)
                5. 在您要驗證的處理程序中,使用@Valid 注釋您要驗證的對象,然后在方法簽名中包含一個BindingResult 以捕獲錯誤.
                1. MVC namespace configuration for annotations: <mvc:annotation-driven />
                2. The JSR-303 spec JAR: validation-api-1.0.0.GA.jar (looks like you already have that)
                3. An implementation of the spec, such as Hibernate Validation, which appears to be the most commonly used example: hibernate-validator-4.1.0.Final.jar
                4. In the bean to be validated, validation annotations, either from the spec JAR or from the implementation JAR (which you have already done)
                5. In the handler you want to validate, annotate the object you want to validate with @Valid, and then include a BindingResult in the method signature to capture errors.

                例子:

                @RequestMapping("handler.do")
                public String myHandler(@Valid @ModelAttribute("form") SomeFormBean myForm, BindingResult result, Model model) {
                    if(result.hasErrors()) {
                      ...your error handling...
                    } else {
                      ...your non-error handling....
                    }
                }
                

                這篇關于javax.validation.constraints 中的注釋不起作用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用錯誤)
                Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 語句 - 是“或/“和可能的?)
                Java Replace Character At Specific Position Of String?(Java替換字符串特定位置的字符?)
                What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作數的三元表達式的類型是什么?)
                Read a text file and store every single character occurrence(讀取文本文件并存儲出現的每個字符)
                Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉換 char 原語?)

                  • <bdo id='3cJEw'></bdo><ul id='3cJEw'></ul>

                    <small id='3cJEw'></small><noframes id='3cJEw'>

                      <tbody id='3cJEw'></tbody>

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

                        <legend id='3cJEw'><style id='3cJEw'><dir id='3cJEw'><q id='3cJEw'></q></dir></style></legend>
                          主站蜘蛛池模板: 一区二区三区在线播放视频 | 波多野结衣精品 | 亚洲成人精品视频 | 国产精品一区二区久久久久 | 久久99精品视频 | 日韩有码一区 | 国产亚洲第一页 | 亚洲一二三区免费 | 国产精品久久影院 | 91免费观看 | 日韩视频在线一区 | 日韩一区中文字幕 | 国产一区久久精品 | 国产区一区 | 91精品国产综合久久久久蜜臀 | 午夜精品久久久久久不卡欧美一级 | 亚洲va欧美va天堂v国产综合 | 免费黄色片视频 | 国产一区二区三区 | 日韩av啪啪网站大全免费观看 | 国产精品一区二区福利视频 | 国产亚洲网站 | 精品视频在线观看 | 人成久久 | 亚洲一区在线日韩在线深爱 | 91精品一区二区三区久久久久 | 欧美在线国产精品 | 亚洲一二三区在线观看 | 国产欧美一区二区三区久久手机版 | 日韩在线不卡视频 | 91精品国产欧美一区二区 | 亚洲欧美在线观看视频 | 日韩视频一级 | 久久久久久久一级 | 求个av网址| 日韩国产在线观看 | 国产伦精品一区二区三区精品视频 | 国产精品久久久久久久久久免费 | 久久久久国产一级毛片高清网站 | 欧美成人精品二区三区99精品 | 欧美亚洲另类丝袜综合网动图 |