public enum PositionParam {
POSITION_PARAM1(1,"總經理"),
POSITION_PARAM2(2,"銷售經理"),
POSITION_PARAM3(3,"人力資源");
private Integer code;
private String name;
private PositionParam(Integer code,String name){
this.code=code;
this.name=name;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
上面的枚舉類以JSON格式返給前臺後顯示的是
["POSITION_PARAM1","POSITION_PARAM2","POSITION_PARAM2"]
而實際想要得到的數據是
[{name:"總經理",code:1},{name:"銷售經理",code:2},{name:"人力資源",code:3}]
處理辦法:
引入jar依賴
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.60</version>
</dependency>
然後在枚舉類中加入以下註解
@JsonFormat(shape = JsonFormat.Shape.OBJECT)