如何在SpringBoot中使用thymeleaf方法

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

美兰网站制作公司哪家好,找成都创新互联公司!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。成都创新互联公司于2013年开始到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联公司

1.pom.xml添加相应依赖


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

2.application.properties

#thymeleaf
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html; charset=utf-8
spring.thymeleaf.cache=false

3.common.xml文件,注意文件路径




Insert title here


  

my first thymeleaf.

  hello, 

如何在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
 * 还有模板文件中得去掉
 * 所有标签得闭合
 * 
 * */
@Controller
@RequestMapping("/templates")
public class TemplateController {
  
  @RequestMapping("/common")
  public String Common(Map map)
  {
    map.put("name", "天恒");
    return "Common";
  }
}

5.添加app.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 stub
    SpringApplication.run(App.class, args);
  }

}

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


当前题目:如何在SpringBoot中使用thymeleaf方法
网页网址:http://bzwzjz.com/article/jigeso.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 攀枝花网站设计 企业网站设计 成都网站设计 手机网站制作 成都网站制作 成都网站制作公司 高端网站设计 成都品牌网站建设 手机网站建设套餐 网站建设方案 公司网站建设 网站建设公司 成都网站建设 品牌网站建设 成都网站设计制作公司 成都网站制作 重庆网站制作 LED网站设计方案 定制网站设计 网站建设 响应式网站设计 外贸网站建设