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

导读:本篇文章讲解 i18n国际化配置文件配置步骤,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

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

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

  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为对可式换出错类型的注解如下:

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

    配置后运行结果:i18n国际化配置文件配置步骤

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/71217.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!