创建enums文件夹
先创建ILabelValue 文件接口
public interface ILabelValue {
int getValue();
String getLabel();
}
创建枚举文件:ProjectImageStatusEnum(例子)
public enum ProjectImageStatusEnum implements ILabelValue{
RUN(1,"交付"),
SUCCESS(2,"审核通过"),
FAIL(3,"驳回");
private int value;
private String label;
public static ProjectImageStatusEnum getEnumByLabel(String label){
if (StringUtils.isBlank(label)){
return null;
}
String label1 = label.replaceAll("\\s","");
for (ProjectImageStatusEnum item : ProjectImageStatusEnum.values()){
if (StringUtils.equalsAnyIgnoreCase(label1,item.getLabel())){
return item;
}
}
return null;
}
public static String getEnumlabelByValue(Integer value) {
if (value == null) {
return StringUtils.EMPTY;
}
for (ProjectImageStatusEnum item : ProjectImageStatusEnum.values()) {
if (item.getValue() == value) {
return item.getLabel();
}
}
return StringUtils.EMPTY;
}
ProjectImageStatusEnum(int value, String label) {
this.label = label;
this.value = value;
}
/**
* @return
*/
public int getValue() {
return value;
}
/**
* @return
*/
public String getLabel() {
return label;
}
}
在controller里使用
@GetMapping(value = "/imagelist")
//TableDataInfo 不固定
public TableDataInfo time(StProjectImage stImage){
startPage();
List<StProjectImage> imageList = imageService.selectProjectImage(stImage);
List<StProjectImage> resData = new ArrayList<>();
for (StProjectImage stProjectImage : imageList) {
stProjectImage.setStatusName(ProjectImageStatusEnum.getEnumlabelByValue(stProjectImage.getApprovedStatus()));
resData.add(stProjectImage);
}
return getDataTable(resData);
}