@RunWith(SpringRunner.class) @SpringBootTest public class BravolinksCrmServerApplicationTests { @Autowired private SqlSessionFactory sqlSessionFactory; @Test public void contextLoads() throws SQLException { Connection conn = sqlSessionFactory.openSession().getConnection(); DatabaseMetaData data = conn.getMetaData(); ResultSet rs = data.getColumns(null,null,"PM_DUOCIDUIZHANG","%"); // while (rs.next()){ // //打印字段name信息 // System.out.println(rs.getString("COLUMN_NAME")); // } //遍历resultset List<Map<String,Object>> list = new ArrayList<>(); ResultSetMetaData rsmd = rs.getMetaData(); int count = rsmd.getColumnCount(); while (rs.next()) { Map rowData = new HashMap();//声明Map for (int i = 1; i <= count; i++) { System.out.println(rsmd.getColumnName(i)+"="+rs.getObject(i)); rowData.put(rsmd.getColumnName(i), rs.getObject(i));//获取键名及值 } list.add(rowData); } System.out.println("list = " + list.size()); } }