java - Spring引用JDBC缺陷?

标签 java spring jdbc

我刚刚阅读了 Spring Data JDBC 引用资料,想知道其中是否存在缺陷。

http://docs.spring.io/spring-data/jdbc/docs/1.1.0.RELEASE/reference/html/core.support.html 下面是示例代码:

private static class CustomerMapper implements RowMapper<Customer> {

  public Customer mapRow(ResultSet rs, int rowNum) throws SQLException {
    Customer c = new Customer();
    c.setId(rs.getInt("customer.id"));
    c.setName(rs.getString("customer.name"));
    return c;
  }
}

该方法会传递两个参数(ResultSet rsint rowNum),而 rowNum 根本不使用。 rowNum 是否还有代码中未见的其他用途?

感谢和问候,

Whit3hat

最佳答案

mapRow(ResultSet rs, int rowNum) 方法是 RowMapper 接口(interface)的一部分。

据我所知(通过快速浏览 Spring Framework 的源代码),任何实现类都不会将其用于日志记录以外的目的。我想它出现在方法签名中是为了给编写实现 RowMapper 接口(interface)的类的开发人员提供更多选择。

关于java - Spring引用JDBC缺陷?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28738575/

相关文章:

java - ESCPOS 打印机图像输出故障

java - 尝试将用户输入与文本文件进行比较,然后在java上读取该点的数字值

java - Spring 数据休息 : Detected multiple association links with same relation type

java - 在 JPA/Hibernate 中执行只读操作的最佳实践是什么?

java - 使用 JDBC 插入或更新表

java - Class.forName ("com.mysql.jdbc.Driver"中的 ClassNotFoundException .newInstance() 与 java applet 相关

java - 用Java编写一个简单的打印方法用于调试

java - 在 JavaFX 中使用 Google map 和街景 View

mysql - Hibernate 4 + Spring 3.2 + 事务管理器 + Mysql 中无回滚

java - 在 MySQL JDBC 准备语句中使用 "zero"时间戳(在 WHERE 子句中)