2017-02-17 5 views
0

プロパティにすべてのエラーメッセージを表示しようとしています。 https://www.mkyong.com/spring-mvc/spring-3-mvc-and-jsr303-valid-example/Spring 4 MVC JSR303プロパティへの@validエラーメッセージ

問題:エラーメッセージは、私のプロパティファイルから来ていないチュートリアル後

enter image description here

POJO

import javax.validation.constraints.DecimalMin; 
import javax.validation.constraints.NotNull; 
import javax.validation.constraints.Pattern; 
import javax.validation.constraints.Size; 

@Entity 
@Table(name="books") 
public class Book implements Serializable{ 

private static final long serialVersionUID = -2042607611480064259L; 

@Id 
@GeneratedValue 
private int id; 

@NotNull 
@Size(min=7) 
private String name; 

@NotNull 
@Size(min=2, max=13) 
private String ispn; 

@DecimalMin(value = "0.01") 
private double price; 

public Book(){} 


// Setter & getters 

} 

exception_en_US.properties

NotNull.book.name = Book name must not be blank, Please insert valid book name. 
Size.book.name = Book name should have more than 7 characters. 

NotNull.book.ispn = Must enter valid ISPN code. 
Size.book.ispn = Standard ISPN code should have 10, 13 characters. 

DecimalMin.book.price = Price of the book must be greater than 0. And can not be Negative number. 

アプリ-ディスパッチャ-servlet.xml

:私は

間違ったファイル構造をしていますかわかりません
<context:component-scan base-package="com.app.controller" /> 

<mvc:annotation-driven/> 

<bean id="localeResolver" 
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> 
    <property name="defaultLocale" value="en" /> 
</bean> 

<mvc:interceptors> 
    <bean id="localeChangeInterceptor" 
     class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
     <property name="paramName" value="language" /> 
    </bean> 
</mvc:interceptors> 

<!-- Binding properties to context --> 

<bean id="messageSource" 
    class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basenames"> 
     <list> 
      <value>com.app.properties.windows</value> 
      <value>com.app.properties.exceptions</value> 
     </list> 
    </property> 

</bean> 

私は間違っていますか?あなたの余分な目は非常に高く評価されます。

ありがとうございました

+0

メールボックスに送信できますか?ありがとう – lpgad

+0

私のeclipseプラグインは常にインストールされていないので – lpgad

答えて

0

:このような何かを試してみてください。

これは私のHTMLで

<sf:form action="/newbook" modelAttribute="formBook" method="POST"> 
     <table> 
     <tr> 
      <td>Book Name:</td> 
      <td> 
       <sf:input type='text' name='name' path="name"/><br/> 
       <sf:errors path="name"></sf:errors> 
      </td> 
     </tr> 
     <tr> 
      <td>ispn:</td> 
      <td> 
       <sf:input type='text' name='ispn' path="ispn"/><br/> 
       <sf:errors path="ispn"></sf:errors> 
      </td> 
     </tr> 
     <tr> 
      <td>Price:</td> 
      <td> 
       <sf:input type='text' name='price' path="price"/><br/> 
       <sf:errors path="price"></sf:errors> 

      </td> 
     </tr> 
     <tr><td colspan='2'><input name="submit" type="submit" value="submit"/></td></tr> 

     </table> 
    </sf:form> 

お知らせ:modelAttribute="formBook"

だから私のexception_en_US.properties

NotNull.formBook.name = Book name must not be blank, Please insert valid book name. 
Size.formBook.name = Book name should have more than 7 characters. 

NotNull.formBook.ispn = Must enter valid ISPN code. 
Size.formBook.ispn = Standard ISPN code should have 10, 13 characters. 

ホープ、これは他の人を助け... ...すっごく長い洙

を連れて行ってくれました
1

あなたのメッセージソース設定が間違っていると思います。それはexception_en_US.propertiesは、クラスとフィールドを参照するが、コマンド名またはmodelAttributeで与えられる&パス名、フォーム名を、形成してはならない結局のところ

<bean id="messageSource" 
    class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basenames"> 
     <list> 
      <value>classpath:window</value> 
      <value>classpath:exception</value> 
     </list> 
    </property> 
</bean> 
+0

私は値が名前を修飾する必要があると思った...編集:私は試した、これは動作しませんでした。私はこのwindow.propertiesをロードしていませんでした.....あなたは私のフォルダのスクリーンショットを撮る必要がありますか?それが助けになるだろうか? –

+0

OK、そうしてください。 – mhshimul

+0

ファイル構造をアップロードしていただきありがとうございます...私のコードは何も間違っていますか? –

関連する問題