利用枚举类进行json输出key value数据格式

public ResponseData customerType() {

ResponseData res = new ResponseData();
try {
CustomerTypeEnums[] customerTypeEnums = CustomerTypeEnums.values();
List<Map<String,String>> list = new ArrayList<>();
for (CustomerTypeEnums customerType : customerTypeEnums){
Map<String,String> map = new HashMap<>();
map.put("custName",customerType.getCustName());
map.put("custCode",customerType.getCustCode());
list.add(map);
}
return ResponseData.ok(list,"查询成功");
} catch (Exception e) {
log.info("查询失败",e.getMessage());
res = ResponseData.fail("查询失败");
}
return res;
}
原文地址:https://www.cnblogs.com/pxzbky/p/14897700.html