Update 28.2. Using JdbcTemplate.md
parent
9441f9c531
commit
afccecfd70
|
@ -0,0 +1,20 @@
|
|||
### 28.2. 使用JdbcTemplate
|
||||
|
||||
Spring的JdbcTemplate和NamedParameterJdbcTemplate类是被自动配置的,你可以在自己的beans中通过@Autowire直接注入它们。
|
||||
```java
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MyBean {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
public MyBean(JdbcTemplate jdbcTemplate) {
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
}
|
||||
// ...
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue