Mybatis如何查询数据库的2列转化为map

1>接口定义

List<Map<String,String>>  changToMap(@Param("reqDto")Student reqDto);

2> xml

SELECT name ,score FROM t_student

3> 处理接口返回值

public class DBToMap {

    public static Map<String, String> listToMap(List<Map<String, String>> list, String key, String value) {
        ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
        for (Map<String, String> temp : list) {
            map.put(temp.get(key), temp.get(value));
        }
        return map;
    }
}

至于如何批量插入、更新或插入、分表批量更新等

猜你喜欢

转载自blog.csdn.net/zhuhaoyu6666/article/details/87782340