velocityに基づいてHTMLを生成する共通の方法。
velocityに基づいてHTMLを生成する共通の方法。
簡単に記念を残しています。長い間忘れがちです。
簡単に記念を残しています。長い間忘れがちです。
/**
* velocity HTML
* @param htmlName
* @param toFilePath
* @param vmTemPath velocity
* @param map
* @param contextName
*/
public void createHtmlByVelocity(String htmlName,String toFilePath,
String vmTemPath,Map<String,Object> params,String contextName){
String filePath=toFilePath+File.separator+htmlName+".html";
try {
FileOutputStream fos = new FileOutputStream(filePath);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
fos, Const.EncodingUTF8));
Template velocity_template =velocityEngine.getTemplate(vmTemPath,Const.EncodingUTF8);
VelocityContext context = new VelocityContext();
context.put(contextName, params);
velocity_template.merge(context,writer );
writer.close();
} catch (Exception e) {
log.error(" !",e);
throw new MYException(" !", e);
}
}
<h2>${list.title}</h2>
<table border="1" style="margin-left: 100px" >
<tr>
<th class="jobs-time"> </th>
<th class="jobs-title"> </th>
<th class="jobs-title">mobileNo</th>
<th class="jobs-title">email</th>
<th class="jobs-title"> ------${list.test}---asasddd</th>
</tr>
#foreach($course in ${list.list})
<tr>
<td width="13%" align="center">
${course.userId}
</td>
<td>${course.name}</td>
<td>${course.mobileNo}</td>
<td>${course.email}</td>
</tr>
#end
</table>
フロントの使い方はMAPのkeyとvalue方式と似ています。このようにすると便利です。バックグラウンドはテンプレートの場所のコードを減らしてVMに一度に値を返します。