关于freemarker自定义标签作为模板在struts中生成静态html的有关问题

关于freemarker自定义标签作为模板在struts中生成静态html的问题

这个问题其实之前也已经有人问过了类似的:http://bbs.csdn.net/topics/320155882
,但是我还是找不到满意的答案。
详细描述如下:

自定义标签 [@vcms_entity][/@vcms_entity],这个标签只有三个参数,entity,package,id,传入这三个参数后可到数据库取出相应的对象

/**
 * 通用取数据对象模板(entity:类名,需与实际名同,可指定包名package;其他属性名需与类属性名同,因为要调用相应的getter)
 * 
 * @example <@vcms_entity entity="Channel" package="com.vcms.cms.entity" id="1">
 *          </@vcms_entity>
 * 
 * @param entity
 *            类名 必填 该类名大小写正确,例如有一个类是UserInfo,如果写成userInfo或Userinfo都是错误
 * 
 * @param package 包名 选填 默认是com.vcms.cms.entity
 * 
 * @param id
 *            对象对应的id 必填
 * 
 * @author vick
 * 
 */
@Component("vcms_entity")
public class VcmsEntityDirective implements TemplateDirectiveModel {

/**
 * 结果集合
 */
private static final String RESULT = "obj";
private int id;

private BasicService basicService;

@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars,
TemplateDirectiveBody body) throws TemplateException, IOException {
Class<?> clazz = null; // 查找对象
TemplateModel className = null;
String packageName = null;

// 遍历Map
Iterator paramIter = params.entrySet().iterator();
Map.Entry ent;
String paramName;
TemplateModel paramValue;
while (paramIter.hasNext()) {
ent = (Map.Entry) paramIter.next();
paramName = (String) ent.getKey();
paramValue = (TemplateModel) ent.getValue();

// 处理"entity"
if ("entity".equals(paramName)) {
className = paramValue;
}
// 处理"package"
if ("package".equals(paramName)) {
packageName = paramValue.toString().trim();
}

// 处理Id
if ("id".equals(paramName)) {
id = FreeMarkertUtil.getNumberValue(paramName, paramValue)
.intValue();
}
}

/**
 * 设置类
 */
if (null != packageName && !"".equals(packageName)) {
clazz = FreeMarkertUtil.findOutClass(className, packageName);
} else {
clazz = FreeMarkertUtil.findOutClass(className);
}
// 检查id
if (id < 1) {
throw new TemplateModelException(
"The \"id\" parameter is required.And the value of it should be larger than 0");
}

// 查询结果
Object obj = basicService.findById(clazz, id);
// // 找不到对象时,创建空对象
// if (null == obj) {
// try {
// obj = clazz.newInstance();
// } catch (Exception e) {
// throw new TemplateModelException(
// "Found no object with the parameter \"id\"=\"" + id+
// "\",error occured while trying to get newInstance of clazz:\""