====================== 查询指定账户的账户详情 ====================== 实现数据访问接口方法: // 针对t_account表的数据访问接口实现 @Repository public class AccountDao implements IAccountDao { @Resource // 注入JDBC模板 private JdbcTemplate jdbcTemplate; ... // 查询指定账户的账户详情 @Override public Account queryAccount(int accountId) { // 定义SQL语句 String sql = "select * from t_account where account_id = ?"; // 执行SQL语句 Account account = jdbcTemplate.queryForObject( sql, (ResultSet rs, int i) -> { Account acc = new Account( rs.getInt("account_id"), rs.getString("account_name"), rs.getString("account_type"), rs.getDouble("money"), rs.getString("remark"), rs.getDate("create_time"), rs.getDate("update_time"), rs.getInt("user_id")); return acc; }, accountId); // 返回指定账户的账户详情 return account; } ... } 编写测试用例: // 查询账户记录测试类 public class SpringJDBCTestQuery extends SpringJDBCTest { @Resource // 注入数据访问对象 private IAccountDao accountDao; ... // 测试:查询指定账户的账户详情 @Test public void testQueryAccount() { // 查询指定账户的账户详情 Account account = accountDao.queryAccount(1); System.out.println(getClass().getName() + "." + Thread .currentThread().getStackTrace()[1].getMethodName() + ": " + account); } ... } 运行测试用例: cn.tedu.springjdbc.test.SpringJDBCTestQuery.testQueryAccount: Account{accountId=1, accountName='9558872419', accountType='工商银行', money=20000.0, remark='工资', createTime=2022-01-13, updateTime=2022-01-13, userId='1'} 看库。