Spring Boot工程案例(二) - 连接Mysql数据库

首先,在pom.xml中添加对mysql mybatis的依赖



	org.mybatis.spring.boot
	mybatis-spring-boot-starter
	2.0.1



	mysql
	mysql-connector-java



	org.springframework.boot
	spring-boot-starter-jdbc

其次,在application.yml中添加mysql连接和mybatis的配置,其中mybatis.mapperLocations配置的是mybatis sql语句xml路径,mybatis.configuration.log-impl配置的是打印sql log日志

server:
   port: 8763
spring:
   application:
      name: springboot-demo
   datasource:
      url: jdbc:mysql://127.0.0.1:3306/province_city_county?useSSL=true&autoReconnect=true&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
      username: root
      password: password
      driver-class-name: com.mysql.jdbc.Driver

mybatis:
   mapperLocations: classpath:mapper/*.xml
   configuration:
      log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

完整代码见: https://github.com/Abbreviation-g/springboot-demo.git

你可能感兴趣的:(JavaWeb,MySql,Spring,Boot工程学习使用心得)