使用,而不是簡單的queryForList()
的定製RowMapper考慮以下代碼:
JdbcTemplate jdbc = new JdbcTemplate(ds);
List<Map<String,Object>> resultSet =
//Use a custom RowMapper
jdbc.query(dsDetailsIN.get("query").toString(), new RowMapper<Map<String,Object>>() {
@Override
public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
//The map per row
Map<String,Object> map = new HashMap<String,Object>();
//The target date format
DateFormat nice = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//Iterating the columns.
ResultSetMetaData meta = rs.getMetaData();
for(int i = 1; i <= meta.getColumnCount(); ++i) {
Object o = rs.getObject(i);
//If a date use formatted String instead
if(o instanceof Date) {
o = nice.format(o);
}
//put into map.
map.put(meta.getColumnName(i), o);
}
return map;
}
});
來源
2016-02-18 16:13:36
Jan
因此,如果測試在地圖中返回的值是一個日期,並格式化你想要的方式。 –
你能分享你用於輸出的代碼嗎? – Jan