@Test public void save() { User beforeSave = User.builder() .firstName("Слава Cataline") .lastName("Сервлетам Слава!") .email("warnikam@net.net") .hashPassword("UA") .build(); usersRepository.save(beforeSave); System.out.println(beforeSave); }
@Override public void save(User model) { KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update( connection -> { PreparedStatement ps = connection.prepareStatement(SQL_INSERT, new String[] {"id"}); ps.setString(1, model.getFirstName()); ps.setString(2, model.getLastName()); ps.setString(3, model.getEmail()); ps.setString(4, model.getHashPassword()); return ps; }, keyHolder); model.setId(keyHolder.getKey().longValue()); }
UsersRepositoryJdbcTemplateImpl implements UsersRepository { @Override public void save(User model) { KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update( connection -> { PreparedStatement ps = connection.prepareStatement(SQL_INSERT, new String[] {"id"}); ps.setString(1, model.getFirstName()); ps.setString(2, model.getLastName()); ps.setString(3, model.getEmail()); ps.setString(4, model.getHashPassword()); return ps; }, keyHolder); model.setId(keyHolder.getKey().longValue()); } }
UsersRepositoryJdbcTemplateImpl implements UsersRepository { @Override public void save(User model) { KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update( connection -> { PreparedStatement ps = connection.prepareStatement(SQL_INSERT, new String[] {"id"}); ps.setString(1, model.getFirstName()); ps.setString(2, model.getLastName()); ps.setString(3, model.getEmail()); ps.setString(4, model.getHashPassword()); return ps; }, keyHolder); model.setId(keyHolder.getKey().longValue()); } UsersRepositoryJdbcTemplateImpl(DataSource dataSource); }
UsersRepositoryJdbcTemplateImpl implements UsersRepository { @Override public void save(User model) { KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update( connection -> { PreparedStatement ps = connection.prepareStatement(SQL_INSERT, new String[] {"id"}); ps.setString(1, model.getFirstName()); ps.setString(2, model.getLastName()); ps.setString(3, model.getEmail()); ps.setString(4, model.getHashPassword()); return ps; }, keyHolder); model.setId(keyHolder.getKey().longValue()); } UsersRepositoryJdbcTemplateImpl(DataSource dataSource); @Override Optional<User> findOne(Long id); @Override void save(User model); @Override void delete(Long id); @Override List<User> findAll(); }
UsersRepositoryJdbcTemplateImpl implements UsersRepository { @Override public void save(User model) { KeyHolder keyHolder = new GeneratedKeyHolder(); jdbcTemplate.update( connection -> { PreparedStatement ps = connection.prepareStatement(SQL_INSERT, new String[] {"id"}); ps.setString(1, model.getFirstName()); ps.setString(2, model.getLastName()); ps.setString(3, model.getEmail()); ps.setString(4, model.getHashPassword()); return ps; }, keyHolder); model.setId(keyHolder.getKey().longValue()); } UsersRepositoryJdbcTemplateImpl(DataSource dataSource); @Override Optional<User> findOne(Long id); @Override void save(User model); @Override void delete(Long id); @Override List<User> findAll();  }