当前位置:网站首页>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 :

边栏推荐
- Information System Project Manager - Chapter VIII project quality management
- MySQL information schema learning (I) -- general table
- Standardized QCI characteristics
- 22-07-05 七牛云存储图片、用户头像上传
- 5. 無線體內納米網:十大“可行嗎?”問題
- Li Kou 101: symmetric binary tree
- 腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
- 手把手教你学会js的原型与原型链,猴子都能看懂的教程
- 爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
- 系统与应用监控的思路和方法
猜你喜欢
![[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)](/img/1e/b270a81c8457f1eae34f55c004a01a.png)
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)

语音识别(ASR)论文优选:全球最大的中英混合开源数据TALCS: An Open-Source Mandarin-English Code-Switching Corpus and a Speech

Redisson bug analysis

Example of shutter text component

Cesium 点击绘制圆形(动态绘制圆形)

2022年6月语音合成(TTS)和语音识别(ASR)论文月报

BUUCTF---Reverse---easyre
腾讯架构师首发,2022Android面试笔试总结

腾讯T3大牛手把手教你,大厂内部资料

企业精益管理体系介绍
随机推荐
Monthly report of speech synthesis (TTS) and speech recognition (ASR) papers in June 2022
What happened to the kernel after malloc() was transferred? Attached malloc () and free () implementation source
某东短信登录复活 安装部署教程
golang的超时处理使用技巧
Tensorflow2.0 self defined training method to solve function coefficients
beegfs高可用模式探讨
2022年6月语音合成(TTS)和语音识别(ASR)论文月报
深度学习分类网络 -- ZFNet
Vmware虚拟机无法打开内核设备“\\.\Global\vmx86“的解决方法
HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
腾讯字节等大厂面试真题汇总,网易架构师深入讲解Android开发
Learning and Exploration - Seamless rotation map
HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
腾讯云数据库公有云市场稳居TOP 2!
After solving 2961 user feedback, I made such a change
POJ 3207 Ikki&#39; s Story IV – Panda&#39; s Trick (2-SAT)
转让malloc()该功能后,发生了什么事内核?附malloc()和free()实现源
MySQL must know and learn
LeetCode_ Double pointer_ Medium_ 61. rotating linked list
Example of applying fonts to flutter