Spring在代码中获取国际化信息
来源:互联网 发布:阿里云飞天八部 编辑:程序博客网 时间:2024/04/27 23:09
实现接口ApplicationContextAware
说明:实现该接口的setApplicationContext(ApplicationContext context)方法,并保存ApplicationContext 对象。
Spring初始化时,会通过该方法将ApplicationContext对象注入。
import java.util.Locale;import org.springframework.context.ApplicationContext;import org.springframework.context.ApplicationContextAware;import org.springframework.context.NoSuchMessageException;public class GnericUtils implements ApplicationContextAware { private static ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { applicationContext = applicationContext; } public static String getMessage(String code) { return getMessage(code, (Object[])null, (Locale)null); } public static String getMessage(String code, String defaultMessage) { return getMessage(code, (Object[])null, defaultMessage, (Locale)null); } public static String getMessage(String code, Object[] args) { return getMessage(code, args, (Locale)null); } public static String getMessage(String code, Object[] args, String defaultMessage, Locale locale) { return applicationContext.getMessage(code, args, defaultMessage, locale); } public static String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException { return applicationContext.getMessage(code, args, locale); }}
以上方法需要在xml文件中配置bean。
2 0
- Spring在代码中获取国际化信息
- Spring MVC在代码中获取国际化信息
- Spring在代码中国际化
- spring mvc中,如何在 Java 代码里,获取 国际化 内容
- spring mvc中,如何在 Java 代码里,获取 国际化 内容
- 新浪旧事-struts2中在各文件中获取国际化信息
- spring ApplicationContext生成和获取国际化信息的方法
- springMVC国际化实现,页面获取错误信息properties中信息
- Spring在代码中获取bean的几种方式
- spring在代码中获取bean的方式
- Spring在代码中获取bean的几种方式
- Spring在代码中获取bean的几种方式
- Spring在代码中获取bean的几种方式
- Spring在代码中获取bean的几种方式
- spring在代码中获取bean的方式
- Spring在代码中获取bean的几种方式
- Spring在代码中获取bean的几种方式
- Spring在代码中获取bean的几种方式
- Linux i2c子系统(四) _从i2c-s3c24xx.c看i2c控制器驱动的编写
- VisualStudio2017下ASP.NET CORE的TagHelper智能提示不能使用的解决办法
- Session分布式共享 = Session + Redis + Nginx
- 使用Compute Shader加速Irradiance Environment Map的计算
- 读书笔记 effective c++ Item 30 理解内联的里里外外 (大师入场啦)
- Spring在代码中获取国际化信息
- [ZooKeeper.net] 1 模仿dubbo实现一个简要的http服务的注册 基于webapi
- RxSwift 入坑好多天
- (@WhiteTaken)UGUI中遇到的一些细碎的知识点
- Alamofire源码解读系列(五)之结果封装(Result)
- WebGIS前端瓦片地图显示原理及实现
- Spring框架(6)---AspectJ实现AOP
- 算法笔记_066:Kruskal算法详解(Java)
- Android学习总结(十二)———— BaseAdapter优化