i18n国际化配置文件配置步骤

i18n(其来源是英文单词 internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称。在资讯领域,国际化(i18n)指让产品(出版物,软件,硬件等)无需做大的改变就能够适应不同的语言和地区的需要。
用上次布属JSR303的为例,继续配置i18n
JSR303数据有效性验证icon-default.png?t=M85Bhttps://mp.csdn.net/mp_blog/creation/editor/127427393

  1. 在Springmvc中配置国际化资源文件
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:mvc="http://www.springframework.org/schema/mvc"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
    		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
    
    	<!-- 必须要使用以下配置才能生效 -->
    	<mvc:annotation-driven />
    	<bean id="messageSource"
    		class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basename" value="i18n"></property>
    	</bean>	
    </beans>

  2. 在src/main/resources中生成一个i18n.properties文件
     

    NotEmpty.user.name \u7528\u6237\u540D\u4E0D\u80FD\u4E3A\u7A7A
    typeMismatch.user.birthday=\u8BF7\u4F7F\u7528\u6B63\u786E\u7684\u65E5\u671F\u683C\u5F0F\uFF0C\u59822009-01-01
    typeMismatch.user.height=\u8BF7\u8F93\u5165\u6570\u5B57

    注:

  • NotEmpty.user.name中 NotEmpty为注解名称、user为类名首字母小写 、name为属性名

  • typeMismatch.user.height 中typeMismatch为对可式换出错类型的注解如下:


    配置后运行结果:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值