如何在SpringBoot中使用thymeleaf方法

  介绍

如何在SpringBoot中使用thymeleaf方法?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

<强> 1.砰的一声。xml添加相应依赖

& lt; dependency>   & lt; groupId> org.springframework.boot   & lt; artifactId> spring-boot-starter-thymeleaf   & lt;/dependency>

<强> 2.应用程序。属性

# thymeleaf   spring.thymeleaf.prefix=类路径://模板   spring.thymeleaf.suffix=. html   HTML5 spring.thymeleaf.mode=spring.thymeleaf.encoding=utf - 8   spring.thymeleaf.content-type=text/html; charset=utf - 8   spring.thymeleaf.cache=false

<强> 3. common.xml文件,注意文件路径

& lt; html>   & lt; head>   & lt; meta  http-equiv=癈ontent-Type",内容=皌ext/html;, charset=UTF-8"/比;   & lt; title> Insert  title  here   & lt;/head>   & lt; body>   & lt;才能h2> my  first  thymeleaf。;/h2>   你好,,才能& lt; span  th:文本=?{名称}“祝辞& lt;/span>   & lt;/body>   & lt;/html>

如何在SpringBoot中使用thymeleaf方法

<强> 4。添加TemplateController。java

package  myshop.controller;      import  java.util.Map;      import  org.springframework.stereotype.Controller;   import  org.springframework.web.bind.annotation.RequestMapping;/*   ,*这里使用@ controller而不是@RestController   ,*还有模板文件中得去掉& lt; ! DOCTYPE  html  PUBLIC “-//W3C//DTD  html  4.01,过渡//EN",“http://www.w3.org/TR/html4/loose.dtd"比;   ,*所有标签得闭合   *大敌;   *,*/@ controller   @RequestMapping (“/templates")   public  class  TemplateController  {   ,,   @RequestMapping才能(“/common")   public 才能;String 常见(字符串,Map,地图)   {才能   ,,,map.put (“name",,“天恒“);   ,,,return “Common";   ,,}   }

<强> 5。添加应用。java

package  myshop;      import  org.springframework.boot.SpringApplication;   import  org.springframework.boot.autoconfigure.SpringBootApplication;      @SpringBootApplication   public  class  App  {   ,,   public 才能;static  void  main (String [], args), {   ,,,//,TODO  Auto-generated  method 存根   ,,,SpringApplication.run (App.class, args);   ,,}      }

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注行业资讯频道,感谢您对的支持。

如何在SpringBoot中使用thymeleaf方法

Copyright © 2020-2023 feiqueyun.cn. All Rights Reserved. 肥雀云_南京肥雀信息技术有限公司版权所有 南京肥雀信息技术有限公司 苏ICP备16063723号-5