JdbcTemplate.update核心源码

    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的应用

posted on 2022-04-02 11:17  金满仓  阅读(85)  评论(0编辑  收藏  举报

导航