使用IDEA创建springboot并集成Thymeleaf

您所在的位置:网站首页 springboot与thymeleaf 使用IDEA创建springboot并集成Thymeleaf

使用IDEA创建springboot并集成Thymeleaf

2024-07-04 02:12| 来源: 网络整理| 查看: 265

创建springboot项目

   记得勾选web

     2.在pom.xml中添加Thymeleaf依赖

org.springframework.boot spring-boot-starter-thymeleaf

  3. 在application.properties修改Thymeleaf相关设置

#路径 spring.thymeleaf.prefix=classpath:/templates/ #后缀 spring.thymeleaf.suffix=.html #编码 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.mode=HTML5

  4.  编写controller

@Controller public class TestController { @RequestMapping("/test") public ModelAndView test(){ ModelAndView modelAndView=new ModelAndView(); modelAndView.setViewName("hello"); List list=new ArrayList(); list.add("zhangsan"); list.add("lisi"); list.add("wangwu"); modelAndView.addObject("list",list); return modelAndView; } }

  5. 在src/main/resource/templates下编写hello.html

Title name

  6.测试

 

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3