spring-boot项目 配置MYSQL驱动
maven pom文件中增加依赖
mysql
mysql-connector-java
runtime
在application.properties中加入配置(注:我的密码数据库密码是空)
#MYSQL链接
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=
在数据库中,新建一张表,放入一丢丢的数据(注意:设计表时,要改表的字符集,排序规则,否则乱码)
在项目中DemoApplication启动类中增加以下代码
packagecom.example.demo;importorg.springframework.boot.SpringApplication;importorg.springframework.boot.autoconfigure.SpringBootApplication;importorg.springframework.context.ConfigurableApplicationContext;importorg.springframework.jdbc.core.Jdbc