SpringMVC 国际化-中英文切换
国际化是为了实现不同地区页面呈现不同的语言问题;
编写程序实现国际化,在xml文件中做响应的配置,然后编写.properties文件即可。
实现登录界面的中英文切换:
xml文件配置:
<!-- 开启注解的功能 加载数据验证配置 、配置国际化的资源、Spring mvc 读取国际化资源--><mvc:annotation-driven validator="validator" conversion-service="conversion-service"/><bean id="conversion-service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/><bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"><property name="basenames" value="message"/></bean><bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/> <mvc:interceptors><bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/> <!-- 需放在拦截器中 --></mvc:interceptors><bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"><property name="providerClass" value="org.hibernate.validator.HibernateValidator"/><property name="validationMessageSource" ref="messageSource"></property></bean>
jsp:
<body><a href="${pageContext.request.contextPath}/login.do?new&locale=zh_CN">中文</a><a href="${pageContext.request.contextPath}/login.do?new&locale=en_us">英文</a></body>
entity实现类通过注解验证:
public class User {@Size(min=3,max=50,message="{fullName}")private String fullName;@Size(min=3,max=20,message="{userName}")//@Pattern(regexp="^[a-zA-Z0-9]+$",message="用户姓名之间不能存在空格") private String userName;@Size(min=6,max=20,message="{password}")private String password;@Pattern(regexp="[A-Za-z0-9._%+-]+@[A-Za-z0-9]+.[A-Za-z]{2,4}",message="{email}")private String email;
properties:
效果:
SpringMVC 国际化-中英文切换相关推荐
- uni-app使用vue-i18n实现国际化(中英文切换)
uni-app使用vue-i18n实现国际化(中英文切换) 1.导入vue-i18n(npm install vue-i18n) 2.创建common文件夹 --> lang.js export ...
- react国际化中英文切换
欢迎关注微信公众号:[ 全栈攻略 ] react项目需要支持国际化,推荐插件"react-intl-universal",原因是"react-intl"存在一些 ...
- SpringMVC实现中英文切换
说明:该配置基于SpringMVC环境搭建的基础上,实现的中英文切换 步骤一:在spring核心配置文件中配置 <!-- 配置国际化语言配置文件 --> <bean name ...
- Qt Quick实现国际化 中英文切换简明图文步骤
目录 前言 一.步骤 1.在pro文件中添加需要生成的ts文件: 2.通过工具-外部-语言家-update 生成zh_CN.ts和en_US.ts 3.通过语言家打开生成的ts文件进行翻译 4.将zh ...
- Android国际化-中英文切换
不想废话,直接上干货 @Overrideprotected void attachBaseContext(Context newBase) {Locale newLocale;if (SPUtil.g ...
- 后台管理系统vue-i18n中英文切换功能
一.vue-i18n是什么? 一款针对Vue.js 的国际化插件.把网站的所有需要中英转换的数据配置成中英文json文件,需要编写大量中英文对照表,适合于少量的固定翻译. 二.使用步骤 1.安装vue ...
- springboot国际化配置中英文切换
1.新建项目 第一步新建springboot项目,勾选web依赖,或者后面进入在pom.xml中加入也可以. 2.项目结构 项目pom.xml <?xml version="1.0&q ...
- SpringBoot中英文切换/国际化——java后端怎么用预置文本的内容替换web网页内容(Resource Bundle)
文章目录 创建预置文件文本内容 Thymeleaf修改前端使其获得预置文本内容 html页面设置跳转标签和传值 创建一个MyLocaleResolver配置文件 在MvcConfiguration中注 ...
- struts2的国际化(即实现网站整体中英文切换)实例
推荐一个专注于Java的小众技术社区:Java之音 环境要求:Struts2框架环境搭建成功 为了实现程序的国际化,必须先提供程序所需要的资源文件.资源文件的内容基本是key-value对,其中key ...
最新文章
- 【自然框架】之“元数据”的威力
- Bug整理——$(window).height()获取到$(document).height()的问题
- python的pypi安装_python pip及安装包安装
- Hadoop中Partition解析
- linux 网络装机,如何搭建和配置PXE网络装机服务
- tail怎么写中文_为什么不能用中文进行编程,而英文却可以?程序员的分析很透彻...
- JAVA中遗留的问题_java中遗留的小问题
- mysql输入密码就闪退_MySQL在我的服务列表里凭空消失~
- Microsoft Edge 浏览器如何打开Axure RP文件
- 第二章 马原刷题(1)
- 常用的评论/帖子/文章排序算法四(牛顿冷却定律)
- js基础 js函数作用域链
- C# NPOI 导出Excel
- linux中python怎么退出_linux 怎么退出python
- oracle blob类型在,Oracle blob类型 实践
- 软考_法律法规与标准化知识
- Python SyntaxError: Non-ASCII character '\xe5' in file
- golang切片简介
- VSCode更新到1.42.1版本有问题(January 2020 (version 1.42))
- 瓜子二手车 翻页 csv