我正在寻找一种方法来检查模板是否存在,然后再将它返回到带有 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/