1.在IDEA创建springboot项目,有两种方式,一种是先创建maven项目,自己在加入sringboot启动注解和resources目录。另外是直接创建springboot的demo。这里因为网络不好的原因,总是连不上spring的官网,就使用第一种通过maven的方式来创建。
第一种:先打开IDEA,选择quickstart模板
- 修改启动类
- 添加resources目录和配置文件,以及templates目录,用来存放前端展示页面
- 配置properties文件,在该文件中配置数据源和页面展示
#前端页面展示配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
#数据源配置
spring.datasource.url=jdbc:mysql://localhost:3306/spike?serverTimezone=GMT&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
#连接池配置
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
#连接等待超时时间
spring.datasource.maxWait=60000
#配置隔多久进行一次检测(检测可以关闭的空闲连接)
spring.datasource.timeBetweenEvictionRunsMillis=60000
#配置连接在池中的最小生存时间
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
# 打开PSCache,并且指定每个连接上PSCache的大小
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
spring.datasource.filters=stat,wall
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=