Enum枚举类的使用。

一、增加枚举类

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;
	}

点点滴滴,简简单单。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值