SpringBoot连接数据库的配置
application.yml文件配置如下图:
application.yml文件代码如下(注意yml文件中的空格):
spring:
datasource:
#配置MYSQL数据库
url: jdbc:mysql://localhost:3306/mydemo?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
#配置SQL SERVER数据库
#url: jdbc:sqlserver://localhost:1433;DatabaseName=数据库名
#driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
#username: sa
#password: 123456
mybatis:
typeAliasesPackage: com.example.mydemo.entity #实体类路径
mapperLocations: classpath:mapping/*.xml #MyBatis的XML文件路径
configuration:
map-underscore-to-camel-case: true
server:
port: 8087 #配置端口号
thymeleaf.content-type: text/html #配置支持HTML5
thymeleaf.cache: false
thymeleaf.mode: LEGACYHTML5
pom.xml文件中不可缺少连接数据库的依赖
如下图所示:
1.连接mysql所需依赖:
2.连接Sql Server所需依赖: