JdbcTemplate的批量操作

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_33704704/article/details/86525995

批量新增

public void addMainTainConfig(List<MainTainConfig> list){

       final List<MainTainConfig> tempBpplist = list;

       String sql="insert into t_maintain_config(user_id, xxx_id, xxx_id, type)" +

               " values(?,?,?,?)";

       this.getJdbcTemplate().batchUpdate(sql,new BatchPreparedStatementSetter() {

            @Override

            public int getBatchSize() {

                 return tempBpplist.size();

            }

           @Override

           public void setValues(PreparedStatement ps, int i)

                   throws SQLException {

               ps.setString(1, tempBpplist.get(i).getUser_id());

                ps.setInt(2, tempBpplist.get(i).getxxx_id());

                ps.setInt(3, tempBpplist.get(i).getxxx_id());

                ps.setString(4, tempBpplist.get(i).getType());

           }

      });

    }

批量删除

public void deleteMainTainConfig(List<MainTainConfig> list){

       final List<MainTainConfig> tempBpplist = list;

       String sql="delete from t_maintain_config where user_id = ? ";

       this.getJdbcTemplate().batchUpdate(sql,new BatchPreparedStatementSetter() {

            @Override

            public int getBatchSize() {

                 return tempBpplist.size();

            }

           @Override

           public void setValues(PreparedStatement ps, int i)

                   throws SQLException {

               ps.setString(1, tempBpplist.get(i).getUser_id());

           }

      });

    }

猜你喜欢

转载自blog.csdn.net/sinat_33704704/article/details/86525995
今日推荐