使用SpringBoot+Thyemleaf 遇到的问题

本文探讨了在使用Thymeleaf模板时遇到的错误,重点在于Controller层面的注解选择及其与HTML页面返回的关系。作者分享了解决数据未传导致模板解析错误的方法,并介绍了如何在application.properties中正确配置Thymeleaf。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用Thymeleaf 模板时Controller 层要使用@Controller注解,使用RestController注解不会返回html页面

要在application.properties配置文件里面添加Thyemleaf 配置

#返回页面的路径
spring.thymeleaf.prefix=classpath:/templates/
#文件后缀
spring.thymeleaf.suffix=.html
#模式
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.servlet.content-type=text/html
#编码格式
spring.thymeleaf.encoding=utf-8
#不需要缓存
spring.thymeleaf.cache=false
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**

select 默认选中选择下拉框

<form id="save_info_form
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值