spring MVC接受对象中包含enum属性

- 说明:后台使用了fastJson,且希望传递的参数不是枚举的名称(例下面对象:INDUSTRY),则需使用@JSONField(name = “100”)。如果传的的参数就是(INDUSTRY),则默认就能接收。

//前台传递的json对象
{
    "date": "2018",
    "domainCode": "100",
}
public class CommConditionModel implements Serializable {

    /**
     * 日期
     */
    private String date;
    /**
     * 领域编码
     */
    private DomainModel domainCode;

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public DomainModel getDomainCode() {
        return domainCode;
    }

    public void setDomainCode(DomainModel domainCode) {
        this.domainCode = domainCode;
    }
}
public enum DomainModel {
    @JSONField(name = "100")
    INDUSTRY("100", "工业"),
    @JSONField(name = "200")
    TRAFFIC("200","交通运输"),
    @JSONField(name = "300")
    ACCOMMOD_CATER("300","住宿餐饮"),
    @JSONField(name = "400")
    WHOLESAVE_RETAIL("400","批发零售"),
    @JSONField(name = "500")
    EDUCATION("500","教育");

    private final String code;
    private final String name;
    DomainModel(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }
}

你可能感兴趣的:(日常记录)