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

深圳集团网站建设南阳建设工程信息网站

深圳集团网站建设,南阳建设工程信息网站,江西人才网官方网站,seo兼职招聘信息前言 最近看到RuoYi-Vue-Plus翻译功能 Translation的翻译模块配置类TranslationConfig,其中有一个注入TranslationInterface翻译接口实现类的写法让我感到很新颖,但这种写法在Spring 3.0版本以后就已经支持注入List和Map,平时都没有注意到这…

前言

最近看到RuoYi-Vue-Plus翻译功能 Translation的翻译模块配置类TranslationConfig,其中有一个注入TranslationInterface翻译接口实现类的写法让我感到很新颖,但这种写法在Spring 3.0版本以后就已经支持注入ListMap,平时都没有注意到这一块,故此记录一下这种写法。

翻译模块配置类

TranslationConfig这里是翻译配置初始化的地方

package com.ruoyi.framework.config;import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.annotation.TranslationType;
import com.ruoyi.common.translation.TranslationInterface;
import com.ruoyi.common.translation.handler.TranslationBeanSerializerModifier;
import com.ruoyi.common.translation.handler.TranslationHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;/*** 翻译模块配置类** @author Lion Li*/
@Slf4j
@Configuration
public class TranslationConfig {@Autowiredprivate List<TranslationInterface<?>> list;@Autowiredprivate ObjectMapper objectMapper;@PostConstructpublic void init() {Map<String, TranslationInterface<?>> map = new HashMap<>(list.size());for (TranslationInterface<?> trans : list) {if (trans.getClass().isAnnotationPresent(TranslationType.class)) {TranslationType annotation = trans.getClass().getAnnotation(TranslationType.class);map.put(annotation.type(), trans);} else {log.warn(trans.getClass().getName() + " 翻译实现类未标注 TranslationType 注解!");}}TranslationHandler.TRANSLATION_MAPPER.putAll(map);// 设置 Bean 序列化修改器objectMapper.setSerializerFactory(objectMapper.getSerializerFactory().withSerializerModifier(new TranslationBeanSerializerModifier()));}}

可以看到在这个配置类中注入了一个List集合,其类型为TranslationInterface翻译接口

我们来看一下它的实现类

这些实现类定义在common模块的translation包下,分别是部门字典OSS用户名的翻译实现

Spring会扫描TranslationInterface翻译接口实现类注入到List

我们来Debug看一下效果,可以看到TranslationInterface翻译接口的实现类确实全部已经注入进来了

由于@Autowired注解还可以注入BeanMap中,这里我们手动加上Map集合,Debug断点调试一下:

http://www.yayakq.cn/news/280431/

相关文章:

  • 网站后台有安全狗链爱交易平台
  • 网站流量超标wordpress怎么启用sll证书
  • 简述电子商务网站开发的基本流程免费企业logo设计
  • 有一个做5s壁纸的网站关键词seo排名怎么选
  • 按钮特效网站遂宁建设局网站首页
  • 用照片做的ppt模板下载网站好高端网站建设 司法
  • flash网站整站下载网络营销推广
  • 西安网站外包平邑的网站都是谁做的
  • 网站设计时图片怎么做手机免费建站教程
  • 网站总体设计怎么写asp.net网站开发简明教程
  • 遵义网站建设服务罗湖住房和建设局网站官网
  • 网站样板山东东营建设网官方网站
  • 郑州网站托管公司上海十大跨境电商排名
  • 网站系统与程序的链接桂林漓江在哪个县哪个区
  • 如何做房产公司网站动态设计参考网站
  • 网站建设合同 程序企业如何建公司网站
  • 网站建设需要有什么特点大数据精准营销案例
  • 网站域名信息查询热点新闻素材
  • 公司后台网站怎么做营销网格化管理
  • 朝阳区手机网站设计服务z怎么做优惠券网站
  • 河北建设厅网站修改密码在哪常用的网页开发工具
  • 青岛h5建站模板win8建立网站
  • 网站建设策略网站优化及推广公司
  • app需要建网站吗电脑网络游戏
  • 江苏品牌网站建设最新网站查询工具
  • 页面设计简称周口seo推广
  • 创造与魔法官方网站做自己喜欢的事建网站有哪些文件夹
  • 网站制作书籍推荐深圳做棋牌网站建设哪家技术好
  • 哪有做企业网站做企业网站不好混
  • 比较网站建设四川成都网站建设