mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Merge branch '3.1.x'
Closes gh-37208
This commit is contained in:
commit
bced103517
@ -29,26 +29,26 @@ import org.springframework.stereotype.Repository;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@Repository
|
||||
public class ExampleRepository {
|
||||
class ExampleRepository {
|
||||
|
||||
private static final ExampleEntityRowMapper ROW_MAPPER = new ExampleEntityRowMapper();
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public ExampleRepository(JdbcTemplate jdbcTemplate) {
|
||||
ExampleRepository(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void save(ExampleEntity entity) {
|
||||
void save(ExampleEntity entity) {
|
||||
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);
|
||||
}
|
||||
|
||||
public Collection<ExampleEntity> findAll() {
|
||||
Collection<ExampleEntity> findAll() {
|
||||
return this.jdbcTemplate.query("select id, name from example", ROW_MAPPER);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user