我最近从Java 6升级到8,将mySql 5.5升级到5.7,将Spring MVC 2升级到5.0.9。我有以下代码,这些代码在升级之前可以工作。但是现在,如果我尝试返回带有一个条目的Map列表,但是Map为空。但事实是,数据库只有一个可用值。
Map<Integer, String> transmittalIds = new HashMap<Integer, String>();
String query = "";
query.append("SELECT TRANSMITTALID, TRANSMITTALCODE FROM LEADERTRANSMITTAL WHERE ")
.append(" CASENUMBERREPORT = 'N'")
.append(" AND STATUS = 'SENT'");
List<Map<Integer, String>> list = getJdbcTemplate().query(query.toString(), new TransmittalIdMapper());
public static final class TransmittalIdMapper implements RowMapper<Map<Integer, String>>{
@Override
public Map<Integer, String> mapRow(ResultSet rs, int arg1) throws SQLException {
Map<Integer, String> map = new HashMap<Integer, String>();
while(rs.next()){
int transmittalId = rs.getInt("TRANSMITTALID");
String transmittalCode = rs.getString("TRANSMITTALCODE");
map.put(transmittalId, transmittalCode);
}
return map;
}
}
System.out.println("List size: "+list.size());
if( list != null && !list.isEmpty()){
System.out.println("List: "+list.get(0));
System.out.println("Map: "+list.get(0).size());
transmittalIds = list.get(0);
}
以下内容输出: 列表大小:1 列表:{} 地图:0