Java操作mysql,指定返回的类型
public Map<String, GtStation> getGtAllStation() {
return mysqlJdbcTemplate.query("SELECT AREA_CODE,STATIONID,STATIONNAME,ESTLGTUD,NORLATUD FROM gt_station;", new AllGtStation());
}
#创建内部类,指定返回的类型
class AllGtStation implements ResultSetExtractor<Map<String, GtStation>> {
@Override
public Map<String, GtStation> extractData(ResultSet result) throws SQLException, DataAccessException {
Map<String, GtStation> stationMap = new HashMap<>();
while (result.next()) {
GtStation station = new GtStation();
String area_code = result.getString("AREA_CODE");
String stationid = result.getString("STATIONID");
String stationname = result.getString("STATIONNAME");
float estlgtud = result.getFloat("ESTLGTUD");
float norlatud = result.getFloat("NORLATUD");
station.setAreaCode(area_code);
station.setStationId(stationid);
station.setStationName(stationname);
station.setLg(estlgtud);
station.setLt(norlatud);
stationMap.put(stationid, station);
}
return stationMap;
}
}