springboot-Themeleaf代替jsp

本文介绍了在Spring Boot中如何使用Thymeleaf替代JSP,由于内嵌的Servlet容器对JSP的支持有限,Spring Boot推荐使用Thymeleaf。添加Thymeleaf依赖后,在Controller中配置路由,然后在templates目录下创建HTML文件进行页面设计。通过Thymeleaf的标签语法,可以实现与JSP类似的动态效果。启动项目,访问指定URL即可看到Thymeleaf渲染的页面。
摘要由CSDN通过智能技术生成

Jsp在内嵌的servlet容器上运行有一些问题(内嵌tomcat、jetty不支持以jar形式运行jsp,undertow不支持jsp)

Spring boot提供了大量模板引擎,包含FreeMarker、Groovy、Thymeleaf、Velocity和Mustache,springBoot推荐使用Thymeleaf作为模板引擎,因为Thymeleaf提供了完美的springMVC支持。

1.添加依赖

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-thymeleaf</artifactId>

</dependency>

2.添加controller

和jsp的没什么两样

@RequestMapping("/toLogin")

public String toLogin(){

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值