久久久久久久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;
                      }
                }
                

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

                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 規(guī)范 JAR:validation-api-1.0.0.GA.jar(看起來你已經(jīng)有了)
                3. 規(guī)范的實現(xiàn),例如 Hibernate Validation,這似乎是最常用的示例:hibernate-validator-4.1.0.Final.jar
                4. 在要驗證的 bean 中,驗證注釋,來自規(guī)范 JAR 或來自實現(xiàn) JAR(您已經(jīng)完成)
                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模板網(wǎng)!

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

                相關文檔推薦

                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 操作數(shù)的三元表達式的類型是什么?)
                Read a text file and store every single character occurrence(讀取文本文件并存儲出現(xiàn)的每個字符)
                Why do I need to explicitly cast char primitives on byte and short?(為什么我需要在 byte 和 short 上顯式轉(zhuǎn)換 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>
                          主站蜘蛛池模板: 久久国产精品一区二区三区 | 欧美成人一区二区 | 亚洲欧洲日韩 | 欧美在线一区二区三区 | 中文字幕一区二区三区四区 | 羞羞的视频免费观看 | 男女精品久久 | 国产一区二区在线免费观看 | 国产精品久久久久久中文字 | 欧美在线视频免费 | 日本一区二区三区视频在线 | 日韩1区2区| 综合久久综合久久 | 精品三区 | 日韩中文字幕在线免费 | 91天堂| 国产精品日韩一区二区 | 亚洲激情在线观看 | 91爱啪啪| 成人精品一区二区三区中文字幕 | 亚洲一卡二卡 | 黄色一级片在线播放 | 人妖一区 | 国产精品美女久久久久aⅴ国产馆 | 精品在线看 | 国产a区 | av先锋资源 | 日韩在线日韩 | 婷婷精品 | 国产色婷婷久久99精品91 | 国产精品久久国产精品 | 中文字幕成人在线 | 久久精品欧美一区二区三区不卡 | 亚洲乱码一区二区三区在线观看 | 久久久久国色av免费观看性色 | 日韩中文一区二区三区 | 国产欧美精品区一区二区三区 | h视频免费观看 | 中文字幕在线一区 | 亚洲精品二区 | 精品一区二区三区四区外站 |