一、增加枚举类
package com.tcj.common.enums;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public enum EnumActivityType {
/**
* 活动正常
*/
ACTIVITY_TYPE_NORMAL("0", "正常"),
/**
* 活动已取消
*/
ACTIVITY_TYPE_CANCEL("1", "已取消"),
/**
* 活动已结束
*/
ACTIVITY_TYPE_END("2", "已结束");
private String code;
private String description;
EnumActivityType(String code, String description) {
this.code = code;// 数字
this.description = description;// 描述
}
public boolean equals(String code) {
if (this.code.equals(code)) {
return true;
}
return false;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public static List
toList() {
List
result = new ArrayList
();
for (EnumActivityType institution : values()) {
result.add(institution);
}
return result;
}
public static Map
toMap() {
Map
enumDataMap = new HashMap
(); for (EnumActivityType e : EnumActivityType.values()) { enumDataMap.put(String.valueOf(e.getCode()), e.getDescription()); } return enumDataMap; } }
二、SpringMVC控制层
方法一、(1)向页面传值枚举类
@RequestMapping(value = "/prepayLogList")
public String orderList(UserAgent user, @ModelAttribute("query") PrepayLogQuery query,
Model model) {
query.setUserId(user.getId());
prepayLogService.getPagination(query);
<span style="color:#ff0000;"> model.addAttribute("prepayTypeMap", EnumPrepayType.toMap());
model.addAttribute("prepayTypeList", EnumPrepayType.toList());</span>
return "center/fund/prepayLogList";
}
(2)页面将值转换称枚举
<select name="payType">
<option value="">请选择</option>
#foreach(<span style="color:#ff0000;">$e in $!prepayTypeList</span>)
<option value="$<span style="color:#ff0000;">e.code</span>" #if($!{query.payType} == "$e.code") selected="selected" #end)><span style="color:#ff0000;">$e.description</span></option>
#end
</select>
#foreach($item in $query.items)
<span class="xjr06" style="width: 10%;">${velocityCount}</span>
<span class="xjr06" style="width: 15%;"><span style="color:#ff0000;">$!{prepayTypeMap.get($!{item.paytype})}</span></span>
#end
方法二、控制层直接做处理
@RemoteMethod
public Page getList(Map<String, String> param) {
Page page=activityManageBiz.getList(param);
//将状态status转为枚举类型
List<Activity> lst=page.getRows();
Map map=EnumActivityType.toMap();
for(int i=0;i<lst.size();i++){
lst.get(i).setStatus(map.get(lst.get(i).getStatus()).toString());
}
return page;
}
点点滴滴,简简单单。