Thymeleaf - 检查模板是否存在

问题描述 投票:2回答:1

我正在寻找一种方法来检查模板是否存在,然后在Thymeleaf和Spring的视图中返回它。

在我的控制器中,我试图做这样的事情:

String finalTemplate = template.getPrefix() + "/" + templateName;

        try {
            return finalTemplate;
        } catch(TemplateInputException e) {
            logger.debug("Sono qua");
            return templateName;
        }

但例外不是抓住......

spring-boot thymeleaf
1个回答
0
投票

您在此处理异常的方式不适用于模板异常。

在问题部分github中检查以下线程。

https://github.com/thymeleaf/thymeleaf-spring/issues/94

https://github.com/thymeleaf/thymeleaf-spring/issues/81

© www.soinside.com 2019 - 2024. All rights reserved.