久久久久久久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>
                          主站蜘蛛池模板: 日日夜夜精品视频 | 91精品在线播放 | 久久精品二区 | 日本不卡一区二区三区 | 国产精品久久二区 | 91看片在线观看 | 四虎在线视频 | 色综合中文| 免费的网站www | 国产精品国色综合久久 | 日韩视频国产 | 国产精品久久精品 | 一级片视频免费 | 一道本在线 | 欧美日韩1区2区 | 作爱视频免费观看 | 国产精品久久久久久久久久久久午夜片 | 国产伊人精品 | 在线国产一区二区三区 | 男人亚洲天堂 | 久久久久91| 日日噜噜夜夜爽爽狠狠 | 亚洲成人中文字幕 | 精品中文在线 | 国产免费一区二区 | 国产精品美女www爽爽爽 | 精品国产精品国产偷麻豆 | 欧美二区在线 | 大香网伊人 | 成人激情视频免费在线观看 | 黄色在线免费网站 | 91在线免费观看网站 | 91偷拍精品一区二区三区 | 日本三级电影在线看 | 成人av网页 | xxxxx免费视频 | 黄色大片视频 | 国产精品视频久久久 | 亚洲精品日韩欧美 | 久久999 | 中文字幕亚洲一区 |