Velocity:如何部分解析html模板?

时间:2013-10-15 08:57:18

标签: java html spring spring-mvc velocity

Apache的速度模板引擎是否有可能部分解析html模板?

例如:

如果我有这样的模板:

<div class="container">
    <div id="section1">Some content of section 1....</div>
    <div id="section2">Some content of section 2....</div>
</div>

我只想解析section1 div的内容。我怎么能做到这一点?

我正在使用Spring MVC 3.0。

1 个答案:

答案 0 :(得分:2)

没有直接的方法来实现这一点,但您可以使用变量来定义部件并协助部分解析:

<div class="container">
 #if ($model.part1) 
    <div id="section1">Some content of section 1....</div>
 #end
 #if (model.part2) 
    <div id="section2">Some content of section 2....</div>
 #end
</div>

其中模型

public class PartialDef {
boolean part1;
boolean part2;
//setters and getters
}

因此,根据您要包含/排除的html部分,相应地定义和打开/关闭变量。

相关问题