thymeleaf-spring5 javax.servlet.ServletException: Could not resolve view with name

原因是参照了官网教程给viewNames赋值".html,.xhtml",但是我的Controller返回的是"index"字符串,ThymeleafViewResolver就没有处理"index"视图。

https://www.thymeleaf.org/doc/tutorials/3.0/thymeleafspring.html#views-and-view-resolvers-in-spring-mvc

<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
  <property name=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Thymeleaf是一种在Java中使用的模板引擎,它可以在HTML页面上使用Thymeleaf标签来实现动态展示。在Java中使用Thymeleaf需要进行一些基础配置。首先,需要在项目的pom.xml文件中引入Thymeleaf依赖,例如在Spring Boot项目中可以添加以下依赖项: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> ``` 接下来,在项目的resources\templates目录下创建HTML文件,注意要导入Thymeleaf的命名空间,否则无法进行模板的渲染。在HTML文件中可以使用Thymeleaf标签来替换静态内容,实现动态展示。 以下是一个示例的HTML文件,其中嵌入了Thymeleaf的标签: ```html <!doctype html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <p th:text="'hello SpringBoot'">hello thymeleaf</p> </body> </html> ``` 在这个例子中,`th:text`标签可以动态替换`<p>`标签中的内容,使页面展示为"hello SpringBoot"。通过这种方式,Thymeleaf可以方便地实现动态内容的展示。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Java学习之Thymeleaf使用](https://blog.csdn.net/xiaochengxuyuan1/article/details/113693978)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [Java基础总结之Thymeleaf详解](https://blog.csdn.net/huzia/article/details/124336997)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值