thymeleaf 3.0.3とSpring Boot 1.5.1のテンプレートで#requestや#responseなどのWebコンテキストオブジェクトのメソッドを呼び出そうとしています。thymeleafテンプレートのWebコンテキストオブジェクトのメソッドの呼び出しに関する問題
私は継続的にこのようなエラーが出る:
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>
これは一つの例ですが、私はどこでもこれをしようとしますが、これらのエラーが発生します。私は行方不明の作品がありますか?
そうですが、なぜですか? #httpServletRequestではなく#requestを参照しています。 –
thymeleafのバージョンによって異なります。 http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#expression-basic-objectsとバージョン3 #request上:ます:http://www.thymeleafバージョン2では#httpServletRequestのようです。 ORG/DOC /チュートリアル/ 3.0/usingthymeleaf.html#式-基本オブジェクト - しかし、あなたはすでに3 thymeleaf使用主張するので、私はここでの問題についてはよく分かりません。おそらくあなたはあなたが思っているより古いバージョンを使用していますか? – eis