利用枚举类进行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;
}
posted @ 2021-06-17 23:06  猿码哥  阅读(438)  评论(0编辑  收藏  举报