当前位置: 首页 > news >正文

怎么注册网站域名住房和城乡建设部科技发展促进中心网站

怎么注册网站域名,住房和城乡建设部科技发展促进中心网站,自己弄个网站要多少钱,网站建设找哪个好java后端自学错误总结 MessageSource国际化接口总结 MessageSource国际化接口 今天第一次使用MessageSource接口,比较意外遇到了一些坑 messageSource是spring中的转换消息接口#xff0c;提供了国际化信息的能力。MessageSource用于解析 消息#xff0c;并支持消息的参数化… java后端自学错误总结 MessageSource国际化接口总结 MessageSource国际化接口 今天第一次使用MessageSource接口,比较意外遇到了一些坑 messageSource是spring中的转换消息接口提供了国际化信息的能力。MessageSource用于解析 消息并支持消息的参数化和国际化。 Spring 包含两个内置的MessageSource实 现ResourceBundleMessageSource和ReloadableResourceBundleMessageSource。 我是用的是idea工具进行开发 文件中文乱码情况,需要先设置一下idea的编码格式,一定需要设置,要不然直接再文件里面将乱码改成中文会有问题的,出现的问题现象就是第一张图是我没有设置编码的时候的样子,第二张是我改为中文的样子,我按照第二张图运行了代码导致我获得的值是???,4个文号,所以大大家不要和我一样傻直接改文件,按照第三张图配置一下就改为中文了 2.下面是我的代码展示 2.1书写全局异常处理类 /*** program:* description: 全局异常拦截处理类* author: wsw* create: 2023-11-29 10:21**/ Log4j2 ControllerAdvice//控制器增强 public class ExceptionCatch {/*** 捕获异常*/ResponseBodyExceptionHandler({Exception.class})//异常处理器与上面的注解一起使用,可以拦截指定的异常信息public ResponseResult exception(Exception exception) {//获取exception异常的类型exception.printStackTrace();//记录日志log.error(catch exception:{}, exception.getMessage());//返回通用的异常return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,exception.getMessage());} }2.2书写spring工具类 Component public final class SpringUtils implements BeanFactoryPostProcessor, ApplicationContextAware {/** Spring应用上下文环境 */private static ConfigurableListableBeanFactory beanFactory;private static ApplicationContext applicationContext;Overridepublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException{SpringUtils.beanFactory beanFactory;}Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException{SpringUtils.applicationContext applicationContext;}/*** 获取对象** param name* return Object 一个以所给名字注册的bean的实例* throws org.springframework.beans.BeansException**/SuppressWarnings(unchecked)public static T T getBean(String name) throws BeansException{return (T) beanFactory.getBean(name);}/*** 获取类型为requiredType的对象** param clz* return* throws org.springframework.beans.BeansException**/public static T T getBean(ClassT clz) throws BeansException{T result (T) beanFactory.getBean(clz);return result;}/*** 如果BeanFactory包含一个与所给名称匹配的bean定义则返回true** param name* return boolean*/public static boolean containsBean(String name){return beanFactory.containsBean(name);}/*** 判断以给定名字注册的bean定义是一个singleton还是一个prototype。 如果与给定名字相应的bean定义没有被找到将会抛出一个异常NoSuchBeanDefinitionException** param name* return boolean* throws org.springframework.beans.factory.NoSuchBeanDefinitionException**/public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException{return beanFactory.isSingleton(name);}/*** param name* return Class 注册对象的类型* throws org.springframework.beans.factory.NoSuchBeanDefinitionException**/public static Class? getType(String name) throws NoSuchBeanDefinitionException{return beanFactory.getType(name);}/*** 如果给定的bean名字在bean定义中有别名则返回这些别名** param name* return* throws org.springframework.beans.factory.NoSuchBeanDefinitionException**/public static String[] getAliases(String name) throws NoSuchBeanDefinitionException{return beanFactory.getAliases(name);}/*** 获取aop代理对象** param invoker* return*/SuppressWarnings(unchecked)public static T T getAopProxy(T invoker){return (T) AopContext.currentProxy();}/*** 获取当前的环境配置无配置返回null** return 当前的环境配置*/public static String[] getActiveProfiles(){return applicationContext.getEnvironment().getActiveProfiles();}/*** 获取当前的环境配置当有多个环境配置时只获取第一个** return 当前的环境配置*/public static String getActiveProfile(){final String[] activeProfiles getActiveProfiles();return !( activeProfilesnull || (activeProfiles.length 0))? activeProfiles[0] : null;}/*** 获取配置文件中的值** param key 配置文件的key* return 当前的配置文件的值**/public static String getRequiredProperty(String key){return applicationContext.getEnvironment().getRequiredProperty(key);} }2.3书写扫描异常拦截处理类配置类 Configuration ComponentScan(****.****.****.****)//上面异常处理类的路径 public class ExceptionConfig { }2.4书写扫描spring工具类扫描 /*** program:* description: 扫描spring工具类包* author: wsw* create: 2023-11-29 13:19**/ Configuration ComponentScan(****.****.****.****)//上面spring工具类的路径 public class SpringUtilsConfig { } 2.5自定义异常基础类 public class BaseException extends RuntimeException {private static final long serialVersionUID1L;/*** 所属模块*/private String module;/*** 错误码*/private String code;/*** 错误码对应的参数*/private Object[] args;/*** 错误消息*/private String defaultMessage;public BaseException(String module, String code, Object[] args, String defaultMessage){this.module module;this.code code;this.args args;this.defaultMessage defaultMessage;}public BaseException(String module, String code, Object[] args){this(module, code, args, null);}public BaseException(String module, String defaultMessage){this(module, null, null, defaultMessage);}public BaseException(String code, Object[] args){this(null, code, args, null);}public BaseException(String defaultMessage){this(null, null, null, defaultMessage);}Overridepublic String getMessage(){String message null;if (!StringUtils.isEmpty(code)){message MessageUtils.message(code, args);}if (message null){message defaultMessage;}return message;}public String getModule(){return module;}public String getCode(){return code;}public Object[] getArgs(){return args;}public String getDefaultMessage(){return defaultMessage;}} 2.6自定义异常继承基础类 public class UserException extends BaseException {private static final long serialVersionUID 1L;public UserException(String code, Object[] args){super(user, code, args, null);} }2.7获取i18n文件将数据交给pring messageSource /*** 获取i18n资源文件* * author wsw*/ public class MessageUtils {/*** 根据消息键和参数 获取消息 委托给spring messageSource** param code 消息键* param args 参数* return 获取国际化翻译值*/public static String message(String code, Object... args){MessageSource messageSource SpringUtils.getBean(MessageSource.class);return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());} }2.8配置i18n国际化文件messages.properties not.null* 必须填写 user.jcaptcha.error验证码错误 user.jcaptcha.expire验证码已失效 user.not.exists用户不存在/密码错误2.9配置spring资源信息国际化资源文件路径application.yml spring:# 资源信息messages:# 国际化资源文件路径basename: i18n/messages总结 配置idea编码如果springUtils工具类调用报错空指针异常,请扫描一下springUtils这个包,也就是上面写的springUtilsConfig类,否则 beanFactory会一直是空值
http://www.dnsts.com.cn/news/185408.html

相关文章:

  • 雄安优秀网站建设哪家好如何推广运营网站
  • 租车网站建设方案wordpress 网站 上传
  • 做网站怎么兼容所有浏览器网站集群建设的意义
  • 福州市台江区网站免费h5
  • 中国建材网官方网站wordpress搜狗
  • 如何开发手机网站搜索引擎优化举例说明
  • 账户竞价托管公司seo搜索引擎营销工具
  • 建设小的电商网站开源系统公司网站的建站要点
  • 阿里logo设计网站建设公司网站需要多少天
  • 寿宁县建设局网站公司介绍网站怎么做的
  • wordpress外贸网站好用的模板下载用开源吗做的网站可以用吗
  • 网站上传无锡网站建设方案服务
  • 延吉网站开发公司wordpress事件提醒
  • 微商城网页版网站关键词优化哪家正规
  • 民治做网站哪家便宜网站维护要学多久
  • 织梦网站图片怎么修改不了jsp网站开发案例
  • 运营和营销哪个更好兰州网站seo分析
  • 英语网站建设策划书最新新闻热点事件2022年8月
  • 网站建设收费标准市场南宁网站建设云尚网络
  • python做网站多么惠州做网站公司
  • 深圳app开发公司哪家比较好seo自己怎么做
  • 网站 防 恶意注册免费做封面的网站
  • 南通网站制作设计wordpress怎么加地图
  • 松江网站建设哪家好网站定制开发 广州
  • 做58网站怎么赚钱吗中山网站建设工作
  • 做擦边球的网站互联网一线大厂排名
  • 西安做百度网站的高大上设计网站欣赏
  • 手机网站的宽度wordpress 所属分类
  • 这几年做哪个网站致富旅游网站设计风格
  • 网站建设mfdos 优帮云苏州小程序定制开发公司