字典翻譯工具介紹

DircConvertUtil

字典翻譯工具類,支持正向翻譯,方向翻譯,翻譯map,翻譯標籤。
目前只支持Mybatis.

一、使用教程

1.1 添加依賴

在 pom.xml中添加依賴:

<!--yaml jar包-->
<dependency>
    <groupId>org.yaml</groupId>
    <artifactId>snakeyaml</artifactId>
    <version>1.25</version>
</dependency>

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
</dependency>

<!--日誌-->
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
</dependency>

2、控制檯打印日誌

mybatis:
  configuration:
    map-underscore-to-camel-case: true
    # 當查詢數據爲空時字段返回爲null,不加這個查詢數據爲空時,字段將被隱藏
    call-setters-on-nulls: true
    # mybatis 在控制檯打印sql日誌
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  mapper-locations: classpath:mapper/*.xml

1.2 你需要提供什麼接口

1、字典全表掃描接口 selectAll

  <select id="selectAll" resultMap="BaseResultMap">
    select row_id, f_type, f_key, f_value, parent_id, is_leaf, opt_status, opt_sort_by,
    opt_flag, create_by, create_time, update_by, update_time, remark
    from tb_dirc
  </select>

注意:目前你可將標籤翻譯的部分注掉

1.3 你需要修改的地方

1、把test.yml 替換成你的yml,注意此yml非application.yml

//yaml name
private static final String YAML_NAME = "test.yml";

2、將TbDircMapper TbLabelFieldMapper TbDirc分別替換成你的mapper和實體類。 目前可將TbLabelFieldMapper 註釋掉。

3、在test.yml中添加自己的域
添加自己的域,添加待翻譯的字段名和對應的字典類型。

zzq: # 這是域
  popu_type: "10101"
  popuType: "10101"
  sex: "10102"
  religion :  "10107"
jack: # 這是域
  popu_type: "10101" # 翻譯Map數據中的字段
  popuType: "10101"  #翻譯實體中的字段
  sex: "10102"
  marital_status : "10104"
  religion :  "10107"

4、使用方式類型於pageHelper分頁

    @GetMapping("/id")
    public Object getPopu() {
        ResultSetConvert.onWithFresh(2,"zzq"); //設置翻譯次數 和 域
        //ResultSetConvert.onNoFresh(); //不同步、不設翻譯次數;默認只翻譯一次 不使用域 則會使用默認的FIELDNAME_FTYPE_MAP
        //ResultSetConvert.onWithFresh(); //只進行同步
        //ResultSetConvert.onWithFresh(1);//同步、並設翻譯次數爲1
        return popuService.selectPeopleByRowId("faf6e00b7aef11ea9c2c005056b17b89");
    }

二、設計實現

2.1 場景

在這裏插入圖片描述

2.2 疑問

以前翻譯要寫case when或者子查詢才能翻譯,能不能把翻譯過程和業務查詢分離開,只用寫簡單的sql就能完成翻譯呢?
在這裏插入圖片描述

2.3 演示

用法如圖
在這裏插入圖片描述

2.4 思考

在這裏插入圖片描述

2.5 場景與技術

在這裏插入圖片描述

2.6 數據結構

在這裏插入圖片描述

2.7 mybatis 攔截器

在這裏插入圖片描述

2.8 併發安全

在這裏插入圖片描述

2.9 bean 生命週期

在這裏插入圖片描述

2.10 可配置化

在這裏插入圖片描述

三、特別鳴謝

ゝLibra `

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章