1. 加入依赖 spring-boot-starter-jdbc :
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency>
|
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
|
3. 程序中注入JdbcTemplate:
@Repository public class ArticleDAO { @Autowired private JdbcTemplate jdbcTemplate;
}
|