我是 freemarker 的初学者,我想用它来生成一些重复的代码。
从这样一个简单的类:
public class Point {
private Integer x;
private Integer y;
private String name;
}
对于每个属性,我需要生成如下行:
ValueProvider<Point,Integer> x();
ValueProvider<Point,Integer> y();
ValueProvider<Point,String> name();
为此,我有这个简单的模板:
ValueProvider<${clazz},${attrType}> ${attrName}();
然后,我想生成一个像这样的完整类:
public final class PointValueProviders {
public interface PointPropertyAccess extends PropertyAccess<Point>{
ValueProvider<Point,Integer> x();
ValueProvider<Point,Integer> y();
ValueProvider<Point,String> name();
}
public static final PointPropertyAccess POINT_PA= GWT.create(PointPropertyAccess.class);
private PointValueProviders(){}
};
为此,我有一个问题:我不知道如何在像这样的更大模板中应用小模板的次数不确定:
public final ${clazz}ValueProviders {
public interface ${clazz}PropertyAccess extends PropertyAccess<${clazz}>{
//Here, How do I tell freemarker to use the small template???
//ValueProvider<${clazz},${attrType}> ${attrName}();
//ValueProvider<${clazz},${attrType}> ${attrName}();
//ValueProvider<${clazz},${attrType}> ${attrName}();
//ValueProvider<${clazz},${attrType}> ${attrName}();
//etc..
}
public static final ${clazz}PropertyAccess ${clazzUpperCase}_PA= GWT.create(${clazz}PropertyAccess.class);
private ${clazz}ValueProviders(){}
};
任何想法?