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);
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);
相关文章推荐
- C# Spring.Net 使用对象映射(RowMapper)返回数据库查询到的结果集
- spring-使用JdbcTemplate完成查询所有记录-RowMapper
- Spring 使用JdbcTemplate类实现批量查询(RowMapper)
- 关于在Spring下 使用HQL 语句模糊查询的实现方法
- 使用SpecificationBuilder简化Spring Data Jpa的动态查询
- 关于Spring-JPA框架下使用多表查询的应用实例记录
- Spring中JdbcTemplate使用RowMapper(简单明了的代码)
- 在Spring中JdbcTemplate中使用RowMapper
- 使用SpringData JPAQL获取查询结果query.getResultList()读取后EntityManager会自动关闭
- 在Spring Boot中使用Spring-data-jpa实现分页查询
- 使用spring jdbc查询对象
- 使用spring的JdbcTemplate进行查询的三种回调方式的比较
- 在SPRING DATA MONGODB中使用聚合统计查询
- 在Spring中JdbcTemplate中使用RowMapper
- 关于hibernate查询,RowMapper的使用小结
- 在Spring Boot中使用Spring-data-jpa实现分页查询
- 在SPRING DATA MONGODB中使用聚合统计查询
- 怎样在google手机地图中方便使用公交查询功能
- Spring data JPA中使用Specifications动态构建查询
- Spring-JDBC:在使用JdbcTemplate进行条件查询时没有返回数据,但是sql直接在数据库中执行是有数据返回的。