@Test public void addViewSpace(){ ViewSpace space = new ViewSpace(); space.setSpaceName("鼓浪屿"); space.setAddress("厦门"); space.setDescription("厦门鼓浪屿"); viewSpaceDao.addViewSpace(space); assertTrue(space.getSpaceId()>0); }
public void addViewSpace(final ViewSpace viewSpace) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; Object[] params = new Object[] { viewSpace.getSpaceName(),viewSpace.getDescription(),viewSpace.getAddress() }; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); return ps; } }, keyHolder); viewSpace.setSpaceId(keyHolder.getKey().intValue()); }
ViewSpaceDao { public void addViewSpace(final ViewSpace viewSpace) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; Object[] params = new Object[] { viewSpace.getSpaceName(),viewSpace.getDescription(),viewSpace.getAddress() }; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); return ps; } }, keyHolder); viewSpace.setSpaceId(keyHolder.getKey().intValue()); } }
ViewSpaceDao { public void addViewSpace(final ViewSpace viewSpace) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; Object[] params = new Object[] { viewSpace.getSpaceName(),viewSpace.getDescription(),viewSpace.getAddress() }; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); return ps; } }, keyHolder); viewSpace.setSpaceId(keyHolder.getKey().intValue()); }  }
ViewSpaceDao { public void addViewSpace(final ViewSpace viewSpace) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; Object[] params = new Object[] { viewSpace.getSpaceName(),viewSpace.getDescription(),viewSpace.getAddress() }; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); return ps; } }, keyHolder); viewSpace.setSpaceId(keyHolder.getKey().intValue()); }  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 addViewSpace(final ViewSpace viewSpace) { final String sql = "INSERT INTO t_view_space(space_name,description,address) VALUES(?,?,?)"; Object[] params = new Object[] { viewSpace.getSpaceName(),viewSpace.getDescription(),viewSpace.getAddress() }; KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() { public PreparedStatement createPreparedStatement(Connection conn) throws SQLException { PreparedStatement ps = conn.prepareStatement(sql); ps.setString(1, viewSpace.getSpaceName()); ps.setString(2, viewSpace.getDescription()); ps.setString(3, viewSpace.getAddress()); return ps; } }, keyHolder); viewSpace.setSpaceId(keyHolder.getKey().intValue()); }  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);  }