Spring  Velocity 模版生成: jsp 

第一步: spring.xml 配置

<bean id="velocityEngine"

class="org.springframework.ui.velocity.VelocityEngineFactoryBean">

<property name="velocityProperties">

<props>

<prop key="velocimacro.library"></prop>

<prop key="file.resource.loader.cache">false</prop>

<prop key="input.encoding">UTF-8</prop>

<prop key="output.encoding">UTF-8</prop>

</props>

</property>

<property name="resourceLoaderPath">

<value>classpath:template</value>

</property>

</bean>

</beans>

<bean id="cooperationService" class="com.fte.manage.service.impl.CooperationServiceImpl" >

<property name="cooperationDao" ref="cooperationDao" />

<property name="velocityEngine" ref="velocityEngine" />

<property name="tel400Service" ref="tel400Service" />

<property name="phone400Service" ref="phone400Service" />

</bean>

第二步:Java 代码

private VelocityEngine velocityEngine;

public void setVelocityEngine(VelocityEngine velocityEngine) {

this.velocityEngine = velocityEngine;

}

List list =cooperationDao.getFteCooperatonJournalList_v2(paramsHm,i*maxPageItem,maxPageItem);

if(list.size()>0 && list!=null){

Map<String,Object> data = new HashMap<String,Object>();

data.put("list", list);

data.put("total", pageTotal);

data.put("subDomain", subDomain);

data.put("dateTools", new DateTools());

String content =  VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "zufang189Journal.vm", data);

File file = new File(getFileName(paramsHm,i*maxPageItem));

if (file.exists()) {

file.delete();

}

FileUtil.makeParent(file);

FileUtils.writeStringToFile(file, content, "UTF-8");

}