当前位置:网站首页>Enumeration gets values based on parameters
Enumeration gets values based on parameters
2022-07-06 20:04:00 【Mr_ ZhangAdd】
The problem background
Fixed business types are often encountered in business , In the database, its meaning is often identified in numerical order 0- Woman 1- male
Main idea :
Define enumeration 》 Get the value composition in the enumeration map Generate bean》 Get... By context bean Get the corresponding value
enumeration
import lombok.Getter;
import lombok.Setter;
/**
* @author Xuewei.Zhang
* @date 2022/7/5
*/
public enum FlowEnum {
ORDER(0, " Order "),
PROCUREMENT(1, " purchase "),
PRODUCTION(2, " production "),
REIMBURSE(3, " Reimbursement "),
VACATE(4, " Ask for leave "),
;
@Getter
@Setter
private Integer code;
@Getter
@Setter
private String msg;
FlowEnum(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
}
assemble bean
import com.zxw.common.core.base.enums.FlowEnum;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Xuewei.Zhang
* @date 2022/7/5
*/
@Configuration
public class FlowBean {
@Bean("FlowEnumBean")
public Map<String, Integer> FlowEnumBean() {
Map<String, Integer> map = new ConcurrentHashMap<>();
for (FlowEnum flowEnum : FlowEnum.values()) {
map.put(flowEnum.getMsg(), flowEnum.getCode());
}
return map;
}
}
Get the corresponding value
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import java.util.Map;
/**
* @author Xuewei.Zhang
* @date 2022/7/5
*/
@Configuration
public class BeanUtils {
private static ApplicationContext applicationContext;
@Resource
public void setApplicationContext(ApplicationContext applicationContext) {
BeanUtils.applicationContext = applicationContext;
}
public static Integer getCodeByServiceName(String serviceName) {
Map<String, Integer> map = (Map<String, Integer>) applicationContext.getBean("FlowEnumBean");
return map.get(serviceName);
}
}
Use
@Override
@InitInsertInfo
public FlowTypeVO add(FlowTypeVO flowTypeVO) {
// Use
flowTypeVO.setServiceType(BeanUtils.getCodeByServiceName(flowTypeVO.getServiceTypeName()));
flowTypeMapper.insert(flowTypeVO);
return flowTypeVO;
}
test result :
边栏推荐
- Dom 操作
- 腾讯T3大牛手把手教你,大厂内部资料
- Understand yolov1 Part II non maximum suppression (NMS) in prediction stage
- Wonderful coding [hexadecimal conversion]
- 使用ssh连接被拒
- golang的超时处理使用技巧
- HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
- Appx代码签名指南
- New generation garbage collector ZGC
- Database specific interpretation of paradigm
猜你喜欢
Tencent Android development interview, basic knowledge of Android Development
Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
PowerPivot——DAX(初识)
【云原生与5G】微服务加持5G核心网
力扣101题:对称二叉树
[play with Linux] [docker] MySQL installation and configuration
信息系统项目管理师---第八章 项目质量管理
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
【计网】第三章 数据链路层(3)信道划分介质访问控制
Hudi vs Delta vs Iceberg
随机推荐
Standardized QCI characteristics
腾讯字节等大厂面试真题汇总,网易架构师深入讲解Android开发
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
青龙面板白屏一键修复
腾讯架构师首发,2022Android面试笔试总结
Dom 操作
【计网】第三章 数据链路层(4)局域网、以太网、无线局域网、VLAN
语音识别(ASR)论文优选:全球最大的中英混合开源数据TALCS: An Open-Source Mandarin-English Code-Switching Corpus and a Speech
理解 YOLOV1 第二篇 预测阶段 非极大值抑制(NMS)
5. 無線體內納米網:十大“可行嗎?”問題
社招面试心得,2022最新Android高频精选面试题分享
Monthly report of speech synthesis (TTS) and speech recognition (ASR) papers in June 2022
MySQL must know and learn
Cesium 点击绘制圆形(动态绘制圆形)
腾讯T2大牛亲自讲解,跳槽薪资翻倍
小微企业难做账?智能代账小工具快用起来
精彩编码 【进制转换】
Li Kou 101: symmetric binary tree
Recursive implementation of department tree
Logstash expressway entrance