连接数据库
使用Spring Data JPA,需要导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
再根据连接不同数据库,导入不同的数据库连接库
MySQL
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
#数据库连接
spring.datasource.url=jdbc:mysql://localhost:3306/db_***
spring.datasource.username=root
spring.datasource.password=123456
MS SQL
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
spring.datasource.url=jdbc:sqlserver://127.0.0.1:1433;databaseName=db_***
spring.datasource.username=888
spring.datasource.password=123456
#driver可省略,由url的值jdbc:sqserver时框架可自动判别driver
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
Oracle
H2
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
#h2
spring.datasource.url=jdbc:h2:~/test;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
#spring.datasource.url=jdbc:h2:file:D:/roncoo_spring_boot;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=
# is h2 console open or close(default true)
spring.h2.console.enabled=true
# h2 console url(http://{you project url}/h2_console})(default /h2-console)
spring.h2.console.path=/h2_console