【发布时间】:2022-12-22 22:44:00
【问题描述】:
在 Thymeleaf < 3.1 中,我使用下面的表达式来获取请求 URI。
th:classappend="${#arrays.contains(urls, #httpServletRequest.getRequestURI()) ? 'active' : ''}"
它一直有效,直到最近我升级到拉取 Thymeleaf 3.1 的 Spring Boot 3.0。我得到这个例外:
[THYMELEAF][parallel-2] Exception processing template "index": Exception evaluating SpringEL expression: "#arrays.contains(urls, #servletServerHttpRequest.getRequestURI()) ? 'active' : ''" (template: "fragments/header" - line 185, col 6)
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method getRequestURI() on null context object
既然我在 Spring Boot 3.0 中使用 Netty 而不是 Tomcat,现在有什么选择?我无法从here 中得出这一点。
作为一种解决方法,现在要解决这个问题,我正在使用:
@GetMapping ("/")
String homePage(Model model) {
model.addAttribute("pagename", "home");
return "index";
}
和
th:classappend="${pagename == 'home' ? 'active' : ''}"
【问题讨论】:
标签: spring spring-boot thymeleaf spring-thymeleaf