
这个demo主要是跟随B站的SpringBoot教学视频进行编写的,大致相同,小部分个人添加,详细内容可参考B站视频:尚硅谷SpringBoot顶尖教程(springboot之idea版spring boot)_哔哩哔哩_bilibili
操作: 先创建一个简单的SpringBoot项目:可参考:SpringBoot -- idea创建简单的helloWorld项目_DGH2430284817的博客-CSDN博客
pom.xml引入thymeleaf依赖包1.8 3.0.9.RELEASE 2.2.2 org.springframework.boot spring-boot-starter-thymeleaf
创建简单的控制器类(快速开发):
@Controller
public class HelloController {
@RequestMapping("/success")
public String success(Map map){
map.put("name","diaoGH");
return "success";
}
}
创建html文件,放到资源目录下的templates文件夹下(没有就新建)
thymeleaf默认的资源目录为classpath:/templates/
可以从项目依赖包中搜索ThymeleafAutoConfiguration , ThymeleafProperties查看对应配置
创建success.html
Title
MyName:
运行项目:
输入地址:http://127.0.0.1:8080/success
效果:
参考代码(码云):
springboot-web-restfulcrud: 简单的springboot项目,简单前段和restful风格的crud