试了 SqlRunner 一直失败,不知道原因,于是试了如下方法,完美解决。
@Autowired private SqlSessionFactory sqlSessionFactory; public List<Map<String, Object>> executeSql(String sql) throws SQLException { try(var sqlSession = sqlSessionFactory.openSession();) { try(var connection = sqlSession.getConnection();) { List<Map<String, Object>> resultList = new ArrayList<>(); var statement = connection.createStatement(); var resultSet = statement.executeQuery(sql); var metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); while (resultSet.next()) { Map<String, Object> rowMap = new HashMap<>(); for (int i = 1; i <= columnCount; i++) { String columnName = metaData.getColumnLabel(i); Object columnValue = resultSet.getObject(i); rowMap.put(columnName, columnValue); } resultList.add(rowMap); } return resultList; } } }
标签:java,springboot,int,resultSet,3.4,sql,var From: https://www.cnblogs.com/nanfei/p/17195451.html