diff --git a/IV. Spring Boot features/28.2. Using JdbcTemplate.md b/IV. Spring Boot features/28.2. Using JdbcTemplate.md index e69de29..f318d5b 100644 --- a/IV. Spring Boot features/28.2. Using JdbcTemplate.md +++ b/IV. Spring Boot features/28.2. Using JdbcTemplate.md @@ -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; + } + // ... +} +```