public List<DatasetColumn> queryDatasetColumns(String datasetId) { if(StringUtil.isEmpty(datasetId)) { return new ArrayList<DatasetColumn>(); } DatasetDefine dataSet = this.findById(DatasetDefine.class, datasetId); String sql = "select * from (" + dataSet.getSql() + ") where 1=0"; List<DatasetColumn> list = getJdbcTemplate().query(sql, new ResultSetExtractor<List<DatasetColumn>>() { @Override public List<DatasetColumn> extractData(ResultSet rs) throws SQLException, DataAccessException { ResultSetMetaData metaData = rs.getMetaData(); int count = metaData.getColumnCount(); List<DatasetColumn> l = new ArrayList<DatasetColumn>(); for (int i = 0; i < count; i++) { String fieldName = metaData.getColumnName(i + 1).toLowerCase(); // int type = metaData.getColumnType(i + 1); String typeName = metaData.getColumnTypeName(i + 1).toLowerCase(); l.add(new DatasetColumn(fieldName, typeName)); } return l; } }); return list; }
时间: 2024-11-11 14:19:35