List<Map<String, Object>> 获取数据以key-value形式输出给下拉框
/**
* 单列非空查询
* @return
*/
SELECT addList FROM `user` WHERE addList is not null GROUP BY addList;
如图获得数据处理:
@Override
public List<Map<String, Object>> userAddList() {
List<Map<String, Object>> maps = userMapper.userAddList();
List<Map<String, Object>> mapList = new ArrayList<>();
List<String> setList = new ArrayList<>();
for (Map<String, Object> map : maps) {
Map<String, Object> map1 = new HashMap<>();
String keyName = (String) map.get("addList");
if (keyName.contains("||")) {
String[] split = keyName.split("[||]");
for (String str : split) {
Map<String, Object> map2 = new HashMap<>();
if (str != null && !str.isEmpty() && !setList.contains(str)) {
map2.put("addList", str);
setList.add(str);
mapList.add(map2);
}
}
} else {
if (!setList.contains(keyName)) {
map1.put("addList", keyName);
setList.add(keyName);
mapList.add(map1);
}
}
}
return mapList;
}
输出结果为key-value形式:
[{"addList":"1"},{"addList":"2"},{"addList":"3"},{"addList":"4"},{"addList":"5"}]