传递已经显示的参数时,为什么会得到空值?

时间:2018-10-12 11:45:11

标签: spring-mvc handlebars.js handlebars.java

我正在尝试使用辅助功能在spring-mvc中使用把手。

下面是我的html把手模板:

    @Configuration
    @EnableWebSecurity
    public class MyWebSecurityConfig extends WebSecurityConfigurerAdapter {

        @Override
        protected void configure(HttpSecurity http) throws Exception {

            http
                .authorizeRequests()
                    .antMatchers("/admin/**").access("hasRole('admin') and hasIpAddress('127.0.0.1')")
                    .antMatchers("/admin/**").access("hasRole('admin') and hasIpAddress('192.168.1.0/24')")
                    .antMatchers("/admin/**").access("hasRole('admin') and hasIpAddress('0:0:0:0:0:0:0:1')");
        }

    }

以下是我在Java中的注册助手:

<td style="color: black;">\{{index}}</td>
<td style="color: black;">\{{dev_name}}</td>
{{#equality dev_name "a"}}
     <td style="cursor:pointer;color: black;" onclick="location.href='/devboard?uid=\{{mac_address}}&cid=\{{cid}}&mid=1'">
    <a class="LN1 LN2 LN3 LN4 LN5">
    \{{mac_address}} </a>
{{/equality}}

执行时,dev_name显示在表中,但传递的值为null。

我最不了解其背后的原因,可能是因为我不熟悉车把。有人可以指导我如何克服这个问题吗?

先谢谢了。 :)

2 个答案:

答案 0 :(得分:0)

实际上,您正在为转把使用转义格式。 尝试删除前导反斜杠。

\{{dev_name}}将显示{{dev_name}}

{{dev_name}}将解析dev_name并显示它,例如Some dev name(如果为null,则为空)

可能您在\{{index}}上遇到了相同的问题

答案 1 :(得分:0)

经过大量链接后,这是我发现的解决方案:

\{{#equality dev_name "a"}}
     <td style="cursor:pointer;color: black;" onclick="location.href='/devboard?uid=\{{mac_address}}&cid=\{{cid}}&mid=1'">
    <a class="LN1 LN2 LN3 LN4 LN5">
    \{{mac_address}} </a>
\{{/equality}}

这样,我们就可以在我的注册助手中获取dev_name。