spring-boot - Thymeleaf - 检查模板是否存在

标签 spring-boot thymeleaf

我正在寻找一种方法来检查模板是否存在,然后再将它返回到带有 Thymeleaf 和 Spring 的 View 中。

在我的 Controller 中,我试图做这样的事情:

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

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

但异常(exception)不是catch ...

最佳答案

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

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

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

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

关于spring-boot - Thymeleaf - 检查模板是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52139371/

相关文章:

java - 使用 @SentTo 通过 Spring Boot 和 RabbitMq 发送消息

java - Spring Boot 使用 SSL 连接到 Postgresql

java - Spring 启动: Download zipped large files while they are being processed on the server

java - Spring MessageSource 基本名称路径问题

html - Thymeleaf 中的算术运算

java - 使用Spring Boot从Kafka消费时启动gradle项目出错: "java.lang.IllegalStateException: Error processing condition on ..."

java - 无法将对象转换为实体类型

java - 动态填充 thymeleaf 中的列表

javascript - 如何将 thymeleaf 字符串变量传递给 javascript 参数?

java - Thymeleaf:如何在不迭代的情况下从列表或数据库中检索元素?