创建一个springboot项目

1.打开IDEA,点击 +Create New Project. 开始创建一个新项目。

  

2.在左侧菜单找到并点击 Spring Initializr,点击next。注意,这里idea默认使用https://start.spring.io提供的在线模板,所以需要保证网络畅通。

当然也可以选择下面的Custom从指定的链接加载模板。

       这时,就有小朋友要问了。要是没网不就GG了,我还是用eclipse吧。放心,IDEA不可能这么菜。如何在本地搭建spring Initializr服务器,

请自行百度。后面会写一篇教程,先在这里立个flag吧。

3.按实际情况依次填写项目信息。其中Type属性可以下拉选择project或者pom,Packaging属性可下拉选择jar或者war(Maven的东西不需要再提了吧)。

填写完毕后点击 Next。

4.最激动人心的界面来了!!!你可以从左面选择大类,然后在窗口中间勾选需要的依赖。右边可以看到已选择的依赖项。

上边下拉框可以选择Spring Boot的版本,这里使用最新版2.2.0 M4。完成后点击 Next。

这里我选择了“Web”类别下的“Spring Web Starter”、“Template”类别下的“Thymeleaf”以及“SQL”类别下的“Spring Data JPA”和“Mysql Driver”。

      

其余的需要什么就勾选什么 

 5. 终于,最后一步了。设置项目名称Project name 和 工程保存路径 Project location。完成后,点击 Finish。

 

 6.等待IDEA构建好项目后,项目结构如下图所示。根据每个人在第4步选择的依赖不同,目录结构大同小异。

 7.再看看pom.xml,我们需要的依赖都静静的躺在里面。是不是so easy,妈妈再也不用担心我找依赖了。

 

 8.写个简单页面试试新建的工程好不好使。

spring boot,启动。

      9.访问看看效果如何,http://localhost:8080 

application.properties配置模版

# 应用名称
spring.application.name=test
# 应用服务 WEB 访问端口
server.port=8080
# 数据库驱动:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 数据源名称
spring.datasource.name=defaultDataSource
# 数据库连接地址
spring.datasource.url=jdbc:mysql://localhost:3306/blue?serverTimezone=UTC
# 数据库用户名&密码:
spring.datasource.username=***
spring.datasource.password=***
# THYMELEAF (ThymeleafAutoConfiguration)
# 开启模板缓存(默认值: true )
spring.thymeleaf.cache=true
# 检查模板是否存在,然后再呈现
spring.thymeleaf.check-template=true
# 检查模板位置是否正确(默认值 :true )
spring.thymeleaf.check-template-location=true
#Content-Type 的值(默认值: text/html )
spring.thymeleaf.content-type=text/html
# 开启 MVC Thymeleaf 视图解析(默认值: true )
spring.thymeleaf.enabled=true
# 模板编码
spring.thymeleaf.encoding=UTF-8
# 要被排除在解析之外的视图名称列表,⽤逗号分隔
spring.thymeleaf.excluded-view-names=
# 要运⽤于模板之上的模板模式。另⻅ StandardTemplate-ModeHandlers( 默认值: HTML5)
spring.thymeleaf.mode=HTML5
# 在构建 URL 时添加到视图名称前的前缀(默认值: classpath:/templates/ )
spring.thymeleaf.prefix=classpath:/templates/
# 在构建 URL 时添加到视图名称后的后缀(默认值: .html )
spring.thymeleaf.suffix=.html
spring.http.converters.preferred-json-mapper=gson

  


参考链接:https://www.cnblogs.com/little-rain/p/11063967.html

原文地址:https://www.cnblogs.com/2393920029-qq/p/15408335.html