【发布时间】:2017-06-29 06:59:41
【问题描述】:
我正在尝试在 thymeleaf 3.0.3 和 Spring Boot 1.5.1 的模板中调用 Web 上下文对象的方法,例如 #request 和 #response。
我不断收到这样的错误:
org.springframework.expression.spel.SpelEvaluationException: EL1011E: 方法调用:试图在空上下文对象上调用方法方法(java.lang.String)
这是一个控制器:
@Controller
public class Controller {
@RequestMapping(method = RequestMethod.GET, value = "/endpoint", produces = "text/html")
public String customerServiceSignin(Model uiModel, HttpServletRequest request) {
uiModel.addAttribute("attr1", true); // show proper header
uiModel.addAttribute("attr2", false);
return "template";
}
还有一个模板:
<html xmlns:th="http://www.thymeleaf.org">
<div>
<div style="...">
<div class="errorblock" th:unless="${#strings.isEmpty(#request.getAttribute('some_attr'))}" th:utext="${#request.getAttribute('some_other_attr')}"></div>
<form name='f' action="action" method='POST'>
<table>
<tr>
<td>User:</td>
<td><input type='text' name='username' value="" />
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' />
</td>
</tr>
<tr>
<td><input name="submit" type="submit" value="submit" />
</td>
<td><input name="reset" type="reset" />
</td>
</tr>
</table>
</form>
</div>
</div>
</html>
这是一个示例,但在我尝试这样做的任何地方都会遇到这些错误。有没有我遗漏的部分?
【问题讨论】:
标签: java spring spring-boot thymeleaf