simple-starter-dict
# 简介
提供注解简化使用:字典翻译
字典服务提供本地文件json使用(默认)、提供接口调用使用、扩展自定义实现使用
服务类返回参数支持单体字段、列表、实体嵌套
# 引入依赖
<dependencies>
<dependency>
<groupId>cn.iosd</groupId>
<artifactId>simple-starter-dict</artifactId>
<version>Version</version>
</dependency>
</dependencies>
1
2
3
4
5
6
7
2
3
4
5
6
7
# 配置项
simple:
dict:
##字典 缺省项为true
enabled: true
## 调用远程接口获取字典项列表实现类请求接口地址前缀(若为空则注解填写需要完整接口路径)
remoteBaseUrl: http://127.0.0.1:11120
## localDictServiceImpl实现类的本地字典文件目录,默认/dict.json。注:resource资源下
resourceDictFileDir: /dict.json
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 功能项
# 本地文件json字典翻译
# 文件
resources/dict.json
{"leader":[{"value":"1","label":"领导"},{"value":"2","label":"苦工"}],"sex":[{"value":"1","label":"女"},{"value":"2","label":"男"}]}
1
# 示例1
@Schema(description = "性别-默认实现类的json文件调用字典")
@DictField(dictionaryParams = "sex", dictImplClass = LocalDictServiceImpl.class, relatedField = "sexText")
private Integer sex;
private String sexText;
1
2
3
4
5
2
3
4
5
# 远程接口字典翻译
# 示例1
@Schema(description = "隐藏身份-默认远程调用接口实现类字典")
@DictField(dictionaryParams = "http://127.0.0.1:11120/dict/remote/hideIdentity", dictImplClass = RemoteDictServiceImpl.class , relatedField = "hideIdentityText")
private Integer hideIdentity;
private String hideIdentityText;
1
2
3
4
5
2
3
4
5
# 示例2
配置文件:
simple:
dict:
remoteBaseUrl: http://127.0.0.1:11120
1
2
3
2
3
使用:
@Schema(description = "隐藏身份-默认远程调用接口实现类字典")
@DictField(dictionaryParams = "/dict/remote/hideIdentity", dictImplClass = RemoteDictServiceImpl.class, relatedField = "hideIdentityText")
private Integer hideIdentity;
private String hideIdentityText;
1
2
3
4
5
2
3
4
5
# 自定义实现
# 示例
@Schema(description = "身份标识-自定义远程调用接口实现类字典")
@DictField(dictionaryParams = "idCard", dictImplClass = CustomDictServiceImpl.class, relatedField = "idCardText")
private Integer idCard;
private String idCardText;
1
2
3
4
5
2
3
4
5
# 自定义实现类
示例代码:customDictServiceImpl 需继承DictService
@Service
public class CustomDictServiceImpl implements DictService {
private RestTemplate restTemplate = new RestTemplate();
@Override
public List<DictItem> getDictItemList(String dictionaryParams) {
String path = "http://127.0.0.1:11120/simple-demo-dict/dict/custom/" + dictionaryParams;
ResponseEntity<Response<List<DictItem>>> responseEntity = restTemplate.exchange(path, HttpMethod.GET, null, new ParameterizedTypeReference<Response<List<DictItem>>>() {
});
return responseEntity.getBody().getData();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
上次更新: 2024/03/25, 02:28:08