实现类
@Override
public String findAgreement(Integer type) {
switch(TypeEnum.forValue(type)){
case ONE:
Map<String,Object> one=productRecordRepository.findAgreementONE();
String config1 = one.get("config").toString();
return config1;
case TWO:
Map<String,Object> two=productRecordRepository.findAgreementTWO();
String config2 = two.get("config").toString();
return config2;
case THREE:
Map<String,Object> three=productRecordRepository.findAgreementTHREE();
String config3 = three.get("config").toString();
return config3;
default:
return null;
}
定义传参指定字段
package com.eyee.api.channel.dto;
public enum TypeEnum {
ONE(1,"买家须知"),TWO(2,"交易须知"),THREE(3,"商家须知");
private Integer code;
private String message;
TypeEnum(Integer code, String message) {
this.code = code;
this.message = message;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public static TypeEnum forValue(int val){
for (TypeEnum t: values()){
if(t.getCode()==val){
return t;
}
}
return ONE;
}
}