当前位置:网站首页>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 :
边栏推荐
- 【云原生与5G】微服务加持5G核心网
- New generation garbage collector ZGC
- Configuration and simple usage of the EXE backdoor generation tool quasar
- Learning and Exploration - Seamless rotation map
- 数据的同步为每个站点创建触发器同步表
- 广州首个数据安全峰会将在白云区开幕
- Cesium 两点之间的直线距离
- Standardized QCI characteristics
- 语音识别(ASR)论文优选:全球最大的中英混合开源数据TALCS: An Open-Source Mandarin-English Code-Switching Corpus and a Speech
- js获取浏览器系统语言
猜你喜欢
Tencent T3 Daniel will teach you hand-in-hand, the internal information of the factory
5. 无线体内纳米网:十大“可行吗?”问题
New generation garbage collector ZGC
深度学习分类网络 -- ZFNet
PowerPivot - DAX (first time)
力扣101题:对称二叉树
Standardized QCI characteristics
社招面试心得,2022最新Android高频精选面试题分享
Interpretation of Dagan paper
新一代垃圾回收器—ZGC
随机推荐
转让malloc()该功能后,发生了什么事内核?附malloc()和free()实现源
121. The best time to buy and sell stocks
MySql必知必会学习
Period compression filter
Groovy基础语法整理
350. Intersection of two arrays II
信息系统项目管理师---第八章 项目质量管理
腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
学习打卡web
It's enough to read this article to analyze the principle in depth
POJ1149 PIGS 【最大流量】
腾讯云数据库公有云市场稳居TOP 2!
Standardized QCI characteristics
AddressSanitizer 技术初体验
mod_ WSGI + pymssql path SQL server seat
MySQL information schema learning (I) -- general table
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
[infrastructure] deployment and configuration of Flink / Flink CDC (MySQL / es)
String length limit?
Li Kou 101: symmetric binary tree