使用IDEA创建springboot并集成Thymeleaf |
您所在的位置:网站首页 › springboot与thymeleaf › 使用IDEA创建springboot并集成Thymeleaf |
创建springboot项目
记得勾选web 2.在pom.xml中添加Thymeleaf依赖 org.springframework.boot spring-boot-starter-thymeleaf3. 在application.properties修改Thymeleaf相关设置 #路径 spring.thymeleaf.prefix=classpath:/templates/ #后缀 spring.thymeleaf.suffix=.html #编码 spring.thymeleaf.encoding=UTF-8 spring.thymeleaf.mode=HTML54. 编写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 name6.测试
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |