Spring Velocity 模版生成: jsp spring
第一步: spring.xml 配置jsp
<bean id="velocityEngine"ide
class="org.springframework.ui.velocity.VelocityEngineFactoryBean">oop
<property name="velocityProperties">ui
<props>this
<prop key="velocimacro.library"></prop>spa
<prop key="file.resource.loader.cache">false</prop>xml
<prop key="input.encoding">UTF-8</prop>ci
<prop key="output.encoding">UTF-8</prop>get
</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");
}