如何在Spring Boot 中使用JdbcTemplate?

18-08-23 banq
    

1. 加入依赖 spring-boot-starter-jdbc :

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> 
<p>

2. 在application.properties.配置数据源:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/concretepage
spring.datasource.username=root
spring.datasource.password=root
<p>

3. 程序中注入JdbcTemplate:

@Repository
public class ArticleDAO {
    @Autowired
    private JdbcTemplate jdbcTemplate;

} 
<p>