protected int update(final PreparedStatementCreator psc, @Nullable final PreparedStatementSetter pss) { return execute(psc, ps -> { pss.setValues(ps); int rows = ps.executeUpdate(); return rows; }); } //---------------------------------------------------------------------------------------------------------------- public <T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action) { Connection con = DataSourceUtils.getConnection(obtainDataSource()); PreparedStatement ps = psc.createPreparedStatement(con); T result = action.doInPreparedStatement(ps); return result; }
模板模式,回调函数,匿名内部类以及lambda的应用