springboot配置数据库
1,创建springboot项目
引入的pom文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
2,修改application.properties文件
server.port=8848 #配置springboot项目端口
#配置springboot连接数据库
spring.datasource.name=healthapp
spring.datasource.url=jdbc:mysql://localhost:3306/subject?characterEncoding=utf-8&useSSL=false
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
#spring.datasource.password=Mysql123$
spring.datasource.password=root
mybatis.mapperLocations=classpath:mapper/*.xml
3,注意
properties文件中配置的“mybatis.mapperLocations”为访问的sql语句mapper文件
如果为创建的maven项目,在pom文件中添加父依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>