spring_reference/IV. Spring Boot features/28.2. Using JdbcTemplate.md

21 lines
572 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 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;
}
// ...
}
```