您的位置:首页 > 移动开发

Spring 查询中怎样使用RowMapper

2014-04-15 11:39 393 查看
以下直接贴出了代码段,供参考:

public List<BigDecimal> queryForthLvSid(int pev1, int pev2) {
return getSimpleJdbcTemplate().query(queryFourthLv,
new RowMapper<BigDecimal>() {

public BigDecimal mapRow(ResultSet rs, int rowNum)
throws SQLException {
return rs.getBigDecimal("FORTH_SID");
}
}, pev1, pev2);
}

rowmapper是一个可以存放任何对象的集合。

存放Sring类型的list

public List<String> queryStoreSid(BigDecimal fourthLv) {
return getSimpleJdbcTemplate().query(queryStroeInfo,
new RowMapper<String>() {

public String mapRow(ResultSet rs, int rowNum)
throws SQLException {
return rs.getString("STORE_ID");r
}
}, fourthLv);
}

存放object类型的list

return getSimpleJdbcTemplate().getJdbcOperations().query(
queryVisitPlan.toString(), new RowMapper<PointBo>() {
PointBo pointBo;

public PointBo mapRow(ResultSet rs, int rowNum)
throws SQLException {
pointBo = new PointBo();
pointBo.setLat(rs.getBigDecimal("LATITUDE")
.doubleValue());
pointBo.setLon(rs.getBigDecimal("LONGITUDE")
.doubleValue());
return pointBo;
}
}, STORE_ID);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: