1.maven引入對應的jar
<!-- 添加對jdbc 的依賴 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- 添加資料庫驅動 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
2.properties中配置(注意對于高版本的jdbc的class檔案是com.mysql.cj.jdbc.Driver,引入其他,啟動時會報錯)
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/ruoyi?serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
3.直接引入
@Autowired
private JdbcTemplate jdbcTemplate;
就可意識用了
轉載于:https://my.oschina.net/jhb4166/blog/2877583