java 小技巧

list中 根据条件封装成map

private Map<String, List<Map<String, Object>>> formatArts(List<Map<String, Object>> arts) {
        Map<String, List<Map<String, Object>>> results = new HashMap<>();
        if (arts != null && arts.size() > 0) {
            for (int i = 0; i < arts.size(); i++) {
                if (results.containsKey(String.valueOf(arts.get(i).get("section_id")))) {
                    results.get(String.valueOf(arts.get(i).get("section_id"))).add(arts.get(i));
                } else {
                    List<Map<String, Object>> list = new ArrayList<>();
                    list.add(arts.get(i));
                    results.put(String.valueOf(arts.get(i).get("section_id")), list);
                }
            }
        }
        return results;
    }

事务自定义异常
@Transactional(rollbackFor=Exception.class)

你可能感兴趣的:(Mysql)