thymeleaf




  • springboot默认打包为jar包,jar包是一个压缩包,但是jsp不支持在压缩包内编译,因此springboot默认不支持jsp

  • Spring官方支持的服务的渲染模板有Thymeleaf和Freemarker等,Thymeleaf是用来开发Web和独立环境项目的服务器端的Java模版引擎

  • 缺点:Thymeleaf效率不高



表达式


引入Thymeleaf的starter

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

在html文件中引入命名空间




例子

success.html




    
    Title


啊哈哈

去百度

ViewController:

@Controller
public class ViewController {

    @RequestMapping("/haha")
    public String haha(Model model){

        //model中的数据会被自动放到请求域中,相当于request.setAttribute("a",aa)
        model.addAttribute("msg","你好");
        model.addAttribute("link","https://www.bilibili.com");
        return "success";
    }
}




相关