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

Java Velocity:如何部分解析html模板?,java,html,spring,spring-mvc,velocity,Java,Html,Spring,Spring Mvc,Velocity,在Apache的velocity模板引擎中是否可以部分解析html模板 例如: 如果我有这样的模板: <div class="container"> <div id="section1">Some content of section 1....</div> <div id="section2">Some content of section 2....</div> </div> 第1节的一些内容。。。。

在Apache的velocity模板引擎中是否可以部分解析html模板

例如:

如果我有这样的模板:

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

第1节的一些内容。。。。
第2节的一些内容。。。。
我只想解析Section1div的内容。我如何才能做到这一点


我正在使用Spring MVC 3.0来实现这一点。

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

<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>
因此,根据要包含/排除的html部分,相应地定义和打开/关闭变量

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