栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > Java

SpringBoot --thymeleaf简单实例

Java 更新时间:发布时间: 百科书网 趣学号
背景:

        这个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

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/276220.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号