简体   繁体   中英

spring messages.properties uses variable name

Is there a way to use a title instead of a variable name when overriding Spring's default messages using the messages.properties file?

For example, I used this

typeMismatch.java.lang.Integer={0} must be a number.

to create the error message "firstName must be a number.", but I would prefer more readability, like "First Name must be a number.".

Is there any way to do this?

You can customize the property for a specific field of a specific class. Say your model attribute is named foo and it has a property named firstName then you can declare a custom error message for that specific field using:

typeMismatch.foo.firstName=First Name must be a number 

You can see this page for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM