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

边栏推荐
- POJ 3207 Ikki&#39; s Story IV – Panda&#39; s Trick (2-SAT)
- It's enough to read this article to analyze the principle in depth
- MySql必知必会学习
- Interpretation of Dagan paper
- 案例 ①|主机安全建设:3个层级,11大能力的最佳实践
- Linear distance between two points of cesium
- 青龙面板白屏一键修复
- 信息系统项目管理师---第八章 项目质量管理
- 方法关键字Deprecated,ExternalProcName,Final,ForceGenerate
- 5. 无线体内纳米网:十大“可行吗?”问题
猜你喜欢

It's enough to read this article to analyze the principle in depth

An East SMS login resurrection installation and deployment tutorial

Node.js: express + MySQL实现注册登录,身份认证
Tencent Android development interview, basic knowledge of Android Development

腾讯Android面试必问,10年Android开发经验

【计网】第三章 数据链路层(4)局域网、以太网、无线局域网、VLAN

Phoenix Architecture 3 - transaction processing
Tencent architects first, 2022 Android interview written examination summary

Learning and Exploration - Seamless rotation map

Oceanbase Community Edition OBD mode deployment mode stand-alone installation
随机推荐
121. 买卖股票的最佳时机
How to handle the timeout of golang
腾讯字节阿里小米京东大厂Offer拿到手软,老师讲的真棒
logstash高速入口
VMware virtual machine cannot open the kernel device "\.\global\vmx86"
Learn to explore - use pseudo elements to clear the high collapse caused by floating elements
Tencent T3 teaches you hand in hand. It's really delicious
Groovy基础语法整理
Method keywords deprecated, externalprocname, final, forcegenerate
Standardized QCI characteristics
Teach you to learn JS prototype and prototype chain hand in hand, a tutorial that monkeys can understand
In simple terms, interview surprise Edition
Cesium Click to draw a circle (dynamically draw a circle)
范式的数据库具体解释
RT-Thread 组件 FinSH 使用时遇到的问题
String length limit?
Logstash expressway entrance
Social recruitment interview experience, 2022 latest Android high-frequency selected interview questions sharing
Tencent architects first, 2022 Android interview written examination summary
枚举根据参数获取值