Merge pull request #37166 from quaff

* pr/37166:
  Continue polishing

Closes gh-37166
This commit is contained in:
Moritz Halbritter 2023-09-06 14:39:47 +02:00
commit 65c739e00e
1 changed files with 5 additions and 5 deletions

View File

@ -32,26 +32,26 @@ import org.springframework.stereotype.Repository;
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
@Repository @Repository
public class ExampleRepository { class ExampleRepository {
private static final ExampleEntityRowMapper ROW_MAPPER = new ExampleEntityRowMapper(); private static final ExampleEntityRowMapper ROW_MAPPER = new ExampleEntityRowMapper();
private final JdbcTemplate jdbcTemplate; private final JdbcTemplate jdbcTemplate;
public ExampleRepository(JdbcTemplate jdbcTemplate) { ExampleRepository(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate; this.jdbcTemplate = jdbcTemplate;
} }
@Transactional @Transactional
public void save(ExampleEntity entity) { void save(ExampleEntity entity) {
this.jdbcTemplate.update("insert into example (id, name) values (?, ?)", entity.getId(), entity.getName()); this.jdbcTemplate.update("insert into example (id, name) values (?, ?)", entity.getId(), entity.getName());
} }
public ExampleEntity findById(int id) { ExampleEntity findById(int id) {
return this.jdbcTemplate.queryForObject("select id, name from example where id =?", ROW_MAPPER, id); return this.jdbcTemplate.queryForObject("select id, name from example where id =?", ROW_MAPPER, id);
} }
public Collection<ExampleEntity> findAll() { Collection<ExampleEntity> findAll() {
return this.jdbcTemplate.query("select id, name from example", ROW_MAPPER); return this.jdbcTemplate.query("select id, name from example", ROW_MAPPER);
} }