弹簧。访问Thymeleaf中的配置变量。

时间:2018-05-31 12:14:56

标签: java spring thymeleaf

我正在尝试将Spring中的配置变量传递给Thmyleaf模板。我已经使用注释值成功加载了配置文件中的变量,并可以通过System.out输出它。我只是在我的模板中渲染它时遇到了麻烦。

application.yaml

acmeUrl:
   url:         https://www.acme.com

我的控制器

   @Value("${acmeUrl.url}")
   private String acmeUrl;

   //grab from annotation and pass to the view
   modelView.addObject( "acmeUrl", this.acmeUrl );

我的Thmeleaf模板:

<span th:text="${acmeUrl}" />

以上作品。但是当我尝试对返回的查询字符串参数进行条件检查时,我什么也得不回来。

<input type="hidden" name="return" th:value="${param.return != null ? param.return[0] : acmeUrl }" />

我的内联IF在这里看起来是否正确?很确定它是罪魁祸首,但不确定我是否需要更改格式才能使其正常工作?

1 个答案:

答案 0 :(得分:2)

https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#conditional-expressions

根据这个,正确的语法是: th:value =“$ {param.return!= null}?{param.return [0]}:{acmeUrl}”

相关问题