freemarker自定义方法

freemarker自定义方法

@Component
public class OrderTag implements TemplateMethodModelEx {

@Override
public Object exec(List list) throws TemplateModelException {
	Student student = new Student();
	if (list != null && list.size() > 0) {
		student.setName(list.get(0).toString());
		student.setAge(Integer.valueOf(list.get(1)+""));
		student.setSex(list.get(2).toString());

//			student.setAge(111);
	}else {
		throw  new TemplateModelException("Wrong!!!");
	}
	return student;
}
}

实例化对象(前端)

<#assign stuMethod="com.my.OrderTag"?new() />

你可能感兴趣的:(模版)