Freemarker" if"条件为null

时间:2017-04-13 06:32:57

标签: spring spring-mvc freemarker

我正在检查在Spring控制器中设置的freemarker中的属性的值。

    @RequestMapping(value = PATH, method = RequestMethod.GET)
    public String doAction(@RequestParam(name = EMAIL, required = false) String email,
            RedirectAttributes redirectAttributes) {

       //Some actions
      ...
      ...
        redirectAttributes.addAttribute("token", "token");

        return AUTH_OAUTH_PW_PATH + VERIFY_PATH;

    }

The freemarker check is like: 
The html component should appear only if the value of the attribute "token" is not found.

<#if !(token?has_content)>
           <br></br>   
        <div id="divId">
        <p><a href="link" id="id1">Hello</a></p>
        </div>
</#if>

即使没有为令牌设置值,也可以看到ftl超链接。

1 个答案:

答案 0 :(得分:1)

??测试操作符检查对象是否为空

尝试以下操作:

<#if token??>
<#else
        <br></br>   
        <div id="divId">
        <p><a href="link" id="id1">Hello</a></p>
        </div>
</#if>