Spring从菜鸟到高手(四)(下)使用JdbcTemplate类实现批量查询

简介:
我们知道了如何验证登陆和批量更新,那么我再介绍一个功能那就是批量查询
那就要用到

org.springframework.jdbc.core 
Class JdbcTemplate

类的query()这个方法他返回一个List对象,里面存了我们所有的对象数据他接受一个RowMapper类型的对象
 List query(PreparedStatementCreator psc, RowMapper rowMapper) 
          Query using a prepared statement, mapping each row to a Java object via a RowMapper.
实现批量查询我们需要实现RowMapper这个接口

org.springframework.jdbc.core 
Interface RowMapper

All Known Implementing Classes:
ColumnMapRowMapperSingleColumnRowMapper

 这个接口只有一个方法
 Object mapRow(ResultSet rs, int rowNum) 
          Implementations must implement this method to map each row of data in the ResultSet.
他负责对ResultSet的处理返回一个对象,这个对象我们对他进行了打包,每一个MyUser对象里面存了用户名和密码
来看看我的MyUser这个类,里面只有用户名和密码两个成员变量
 10e78569dd6.jpg
RowMapper类的实例MyRowMapper
10e7856047e.jpg
我修改的XML文件加了一个RowMapper Bean
10e785d7b0f.jpg
 
经过修改的核心类
10e785e24b2.jpg








本文转自 tony_action 51CTO博客,原文链接:http://blog.51cto.com/tonyaction/42043,如需转载请自行联系原作者
目录
相关文章
|
2月前
|
XML 存储 Java
Spring重要类解析
Spring重要类解析
23 0
|
2月前
|
Java Spring
使用JDBCTemplate实现与Spring结合,方法公用 ——测试(EmpDaoImplTest)
使用JDBCTemplate实现与Spring结合,方法公用 ——测试(EmpDaoImplTest)
9 0
|
10天前
|
消息中间件 安全 Java
在Spring Bean中,如何通过Java配置类定义Bean?
【4月更文挑战第30天】在Spring Bean中,如何通过Java配置类定义Bean?
19 1
|
15天前
|
安全 Java 测试技术
Spring Boot 自动化单元测试类的编写过程
企业开发不仅要保障业务层与数据层的功能安全有效,也要保障表现层的功能正常。但是我们一般对表现层的测试都是通过postman手工测试的,并没有在打包过程中代码体现表现层功能被测试通过。那么能否在测试用例中对表现层进行功能测试呢?答案是可以的,我们可以使用MockMvc来实现它。
44 0
|
1月前
|
SQL Java 数据库连接
jpa、hibernate、spring-data-jpa、jdbcTemplate
jpa、hibernate、spring-data-jpa、jdbcTemplate
|
2月前
ssm(Spring+Spring mvc+mybatis)Service层实现类——DeptServiceImpl
ssm(Spring+Spring mvc+mybatis)Service层实现类——DeptServiceImpl
10 0
|
2月前
ssm(Spring+Spring mvc+mybatis)Dao层实现类——DeptDaoImpl
ssm(Spring+Spring mvc+mybatis)Dao层实现类——DeptDaoImpl
13 0
|
2月前
|
Java Spring
使用JDBCTemplate实现与Spring结合,方法公用 ——Emp实现类(EmpDaoImpl)
使用JDBCTemplate实现与Spring结合,方法公用 ——Emp实现类(EmpDaoImpl)
8 0
|
2月前
|
Java Spring
使用JDBCTemplate实现与Spring结合,方法公用 ——共用实现类(BaseImpl)
使用JDBCTemplate实现与Spring结合,方法公用 ——共用实现类(BaseImpl)
10 1
|
2月前
|
Java Spring
使用JDBCTemplate实现与Spring结合,方法公用 ——接口(BaseDao)
使用JDBCTemplate实现与Spring结合,方法公用 ——接口(BaseDao)
9 0