SpringBoot -- thymeleaf

Thymeleaf

  • 作为XML/XHTML/HTML5模板引擎,thymeleaf可以替代 Framemarker/JSP等
  • Springboo对thymeleaf的支持也是非常好
  • 其他的标签什么的参考官网

build.gradle中引入 thymeleaf

 compile ('org.springframework.boot:spring-boot-starter-thymeleaf')
 compile ('org.springframework.boot:spring-boot-starter-web')

application.yml 设置 thyemleaf

  • 文件path:resources下的web
  • 文件后缀: .html
spring:
  thymeleaf:
    cache: false
    mode: LEGACYHTML5
    prefix: classpath:/web/
    suffix: .html

Controller 返回内容

  public String testRibbon(String content, ModelMap modelMap) {
        System.out.println(content);
        String resultStr = restTemplate.getForEntity(serverURI+"testRealRibbon?content="+content,String.class).getBody();
        modelMap.addAttribute("result",resultStr);
        return "index";
    }

index.html内容

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>Test the Thymeleaf</h1>
<span th:text = "${result}"></span>
</body>
</html>

可能的错误

  • 引入的jar错误
  • 默认的path为 teamplates
  • path多层目录可能出现的错误

集成FreeMarker

引入 spring-boot-starter-freemarker

compile ('org.springframework.boot:spring-boot-starter-freemarker')

集成JSP

引入 spring-boot-starter-freemarker

compile ('org.springframework.boot:spring-boot-starter-tomcat')
compile ('org.apache.tomcat.embed:tomcat-embed-jasper')
compile ('javax.servlet:jstl')

application.yml中加入jsp配置

spring:
   mvc:
   view:
    prefix: /jsp
    suffix: .jsp

更多集成参考springboot github


代码

代码请移步 Github参考地址

如有疑问请加公众号(K171),如果觉得对您有帮助请 github start
公众号_k171

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值