广告
返回顶部
首页 > 资讯 > 后端开发 > Python >解决Springboot项目打包后的页面丢失问题(thymeleaf报错)
  • 931
分享到

解决Springboot项目打包后的页面丢失问题(thymeleaf报错)

2024-04-02 19:04:59 931人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

目录SpringBoot项目打包后的页面丢失遇到的问题目前找到两种springboot打包ThymeLeaf报错原因解决办法Springboot项目打包后的页面丢失 遇到的问题目前找

Springboot项目打包后的页面丢失

遇到的问题目前找到两种

  • 返回视图路径以/开头,例如 /test/hello
  • 在thymeleaf页面中,引入的页面以/开头,例如:<footer th:replace="/index::footer"></footer>

代码书写规范:


    @GetMapping("/about-us")
    public String sysInfo(){
        return "students/about-us";
    }

错误写法:(不要在前面加入"/")


return "/students/about-us";

引入公共模板时,也不要加''/'

正确写法:


<header th:replace="main/sys-public :: stu-header"></header>

总结:在代码编写的过程中,要注意规范书写习惯,避免不必要的问题发生。

Springboot打包ThymeLeaf报错

开发环境

现象

Boot 打包启动后报如下错

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/login", template might not exist or might not be accessible by any of the configured Template Resolvers at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:870) ~[thymeleaf-3.0.9.RELEASE.jar!/:3.0.9.RELEASE] at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:607) ~[thymeleaf-3.0.9.RELEASE.jar!/:3.0.9.RELEASE] at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1098) [thymeleaf-3.0.9.RELEASE.jar!/:3.0.9.RELEASE] at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1072) [thymeleaf-3.0.9.RELEASE.jar!/:3.0.9.RELEASE] at org.thymeleaf.spring5.view.ThymeleafView.renderFragment(ThymeleafView.java:354) [thymeleaf-spring5-3.0.9.RELEASE.jar!/:3.0.9.RELEASE] ...

判断为模板视图跳转错误

原因

配置文件错误,模板读取路径错误

解决办法

修改ThymeLeaf配置

具体操作

增加红色的部分


thymeleaf:
  mode: html
  cache: false
  prefix: classpath:/templates

<!--公共模板引用 -->
<head th:include="/template/head :: tableHeader"></head>

    
    @apiOperation(value = "请求页面",notes = "获取页面")
    @GetMapping(value = "/page/{pageName}")
    public String page(@PathVariable @ApiParam("页面名称")String pageName, @ApiIgnore Model model){
        initDefaultModel(model);
        String page = pageConfig.getPageMap().get(pageName);
        if(page == null){
            return "/404";
        }
        return page;
    }

开发环境中遗漏可以正常启动跳转,打包后文件结构产生变化需要指定。

参考文档

Spring Boot gives “TemplateInputException: Error resolving template” when running from jar

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: 解决Springboot项目打包后的页面丢失问题(thymeleaf报错)

本文链接: https://www.lsjlt.com/news/157017.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作