mybatis結果返回List集合

1.xml文件


    <select id="selectList"  resultType="java.util.HashMap">
        SELECT *FROM employee
    </select>

2.dao層


        public List<Map<String,Object>> selectList();

3.測試

    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();
        
        
        EmployeeMapper mapper = session.getMapper(EmployeeMapper.class);
        List<Map<String,Object>> selectList = mapper.selectList();
        for (Map<String,Object> map : selectList) {
            for (Map.Entry<String, Object> m : map.entrySet()) {
                System.out.print(m.getKey()+"--"+m.getValue());
            }
        }

    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章