================================== 删除多条账户记录,返回受影响的行数 ================================== 实现数据访问接口方法: // 针对t_account表的数据访问接口实现 @Repository public class AccountDao implements IAccountDao { @Resource // 注入JDBC模板 private JdbcTemplate jdbcTemplate; ... // 删除多条账户记录,返回受影响的行数 @Override public int deleteAccounts(int[] accountIds) { // 定义SQL语句 String sql = "delete from t_account where account_id = ?"; // 执行SQL语句 int nrows = jdbcTemplate.batchUpdate( sql, new BatchPreparedStatementSetter() { // 为第i条待删除记录设置参数 @Override public void setValues(PreparedStatement ps, int i) throws SQLException { // 第i条待删除记录 int accountId = accountIds[i]; // 设置参数 ps.setInt(1, accountId); } // 获取待删除记录数 @Override public int getBatchSize() { return accountIds.length; } } ).length; // 返回受影响的行数 return nrows; } ... } 编写测试用例: // 删除账户记录测试类 public class SpringJDBCTestDelete extends SpringJDBCTest { @Resource // 注入数据访问对象 private IAccountDao accountDao; ... // 测试:删除多条账户记录,返回受影响的行数 @Test public void testDeleteAccounts() { // 删除多条账户记录,返回受影响的行数 int nrows = accountDao.deleteAccounts(new int[] {4, 5, 6, 7}); System.out.println(getClass().getName() + "." + Thread .currentThread().getStackTrace()[1].getMethodName() + ": " + nrows); } ... } 运行测试用例: cn.tedu.springjdbc.test.SpringJDBCTestDelete.testDeleteAccounts: 4 看库。