@Test public void addViewSpaces(){ ViewSpace space1 = new ViewSpace(); space1.setSpaceName("鼓浪屿"); space1.setAddress("厦门"); space1.setDescription("厦门鼓浪屿"); ViewSpace space2 = new ViewSpace(); space2.setSpaceName("植物园"); space2.setAddress("厦门"); space2.setDescription("厦门植物园"); List spaces = new ArrayList<ViewSpace>(); spaces.add(space1); spaces.add(space2); viewSpaceDao.addViewSpaces(spaces); }
public void addViewSpaces(final List<ViewSpace> viewSpaces) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); }
ViewSpaceDao { public void addViewSpaces(final List<ViewSpace> viewSpaces) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); } }
ViewSpaceDao { public void addViewSpaces(final List<ViewSpace> viewSpaces) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); }  }
ViewSpaceDao { public void addViewSpaces(final List<ViewSpace> viewSpaces) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); }  void initDb(); void addViewSpace(final ViewSpace viewSpace); void addViewSpaceByNamedParams(final ViewSpace viewSpace); void addViewSpaces(final List<ViewSpace> viewSpaces); ViewSpace getViewSpace(final int spaceId); List<ViewSpace> getViewSpaces(final int fromId, final int toId); }
ViewSpaceDao { public void addViewSpaces(final List<ViewSpace> viewSpaces) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { public int getBatchSize() { return viewSpaces.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ViewSpace viewSpace = viewSpaces.get(index); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); } }); }  void initDb(); void addViewSpace(final ViewSpace viewSpace); void addViewSpaceByNamedParams(final ViewSpace viewSpace); void addViewSpaces(final List<ViewSpace> viewSpaces); ViewSpace getViewSpace(final int spaceId); List<ViewSpace> getViewSpaces(final int fromId, final int toId);  }