目录
一、IDEA创建SpringBoot项目
1、创建新项目

2、创建springboot项目

当出现json解析问题而无法创建springboot项目,如图

此种情况下的解决方法:改用Custom方式,输入网址https://start.aliyun.com/。如下图:

3、设置项目属性

4、初始化时添加基本的依赖包(web依赖)

5、设置工程路径

6、springboot项目创建完成,下图中红框部分文件可以删除

二、配置全局配置
在application.yml或appplication.properties文件中输入如下配置:

三、thymeleaf模板访问html页面
1、springboot项目在使用thymeleaf模板时默认web入口是在templates文件夹下,在templates文件夹下随便写一个html文件,此处以index.html文件为例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>首页</title>
</head>
<body>
<h1>首页</h1>
</body>
</html>
2、在pom.xml文件中添加thymeleaf依赖
<!--thymeleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
3、创建controller访问控制器,此处在com.example.test_example路径下创建IndexController.java控制器,如下:
/**
* TODO
*
* @author Cll
* @date 2020/6/1
*/
@Controller
public class IndexController {
@GetMapping("/index")
public String index() {
return "index";
}
}
4、运行项目后,在浏览器中输入127.0.0.1:8080/te/index或者localhost:8080/te/index,成功显示的效果图如下所示:

该博客介绍了如何在IntelliJ IDEA中创建SpringBoot项目,并配置全局设置,特别是针对遇到的JSON解析问题给出了解决方案。然后详细阐述了如何配置Thymeleaf模板,包括添加依赖、创建HTML页面、编写Controller以及运行和测试项目。通过这些步骤,读者将能够掌握SpringBoot结合Thymeleaf展示静态页面的方法。
1147

被折叠的 条评论
为什么被折叠?



