Spring Boot (三) Spring Boot for thymeleaf

Spring Boot 其实是不建议我们在spring Boot里使用JSP,具体原因官方文档有,下面是其中一段原文:

27.4.5 JSP Limitations
When running a Spring Boot application that uses an embedded servlet container (and is packaged as an executable archive), there are some limitations in the JSP support.
With Tomcat, it should work if you use war packaging. That is, an executable war works and is also deployable to a standard container (not limited to, but including Tomcat). An executable jar does not work because of a hard-coded file pattern in Tomcat.
With Jetty, it should work if you use war packaging. That is, an executable war works, and is also deployable to any standard container.
Undertow does not support JSPs.
Creating a custom error.jsp page does not override the default view for error handling. Custom error pages should be used instead.
There is a JSP sample so that you can see how to set things up.


Spring Boot thymeleaf

Thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎。类似JSP,Velocity,FreeMaker等,它也可以轻易的与Spring MVC等Web框架进行集成作为Web应用的模板引擎。与其它模板引擎相比,Thymeleaf最大的特点是能够直接在浏览器中打开并正确显示模板页面,而不需要启动整个Web应用。它的功能特性如下:

  • Spring MVC中@Controller中的方法可以直接返回模板名称,接下来Thymeleaf模板引擎会自动进行渲染
  • 模板中的表达式支持Spring表达式语言(Spring EL)
  • 表单支持,并兼容Spring MVC的数据绑定与验证机制

1. 引入依赖

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

这里写图片描述


使用体验

首先说明一下,本人是属于后端开发人员,使用了一下thymeleaf觉得不太适合现在的自己用。
原因如下:thymeleaf标签是属于前端的范畴,本人前端水平一般,所以用起来觉得比较难用,jsp本质上还是Java 代码,所以感觉还是jsp好用,JSP 是JavaEE的规范,但JSP 显然已经out 了。毕竟不合适前后端分离的项目。
引用:http://www.imooc.com/article/20304

http://blog.csdn.net/mygzs (有客友已经写得很好了)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值