【发布时间】:2011-12-21 00:56:06
【问题描述】:
我正在尝试做一个模板,给定一些属性,为所有字段生成“特殊”的 getter 和 setter。
例如,
public class MyBean {
private int numeric;
}
生成这个:
public int getNumeric() {
return numeric;
}
public void setNumeric(final int newNumeric) {
this.numeric = newNumeric;
}
我检查了默认的 Eclipse 模板是否使用变量 ${body_statement} 来生成 setter 和 getter,我认为我需要更改这个变量但我没有找到这个变量的表达式。
我尝试使用以下模板,但它不能正常工作(我必须手动编写类型和字段)。
private ${type} get${field}() {return ${field};}
private void set${field}(final ${type} ${field}) {this.${field} = ${field};}
有人有想法吗?
谢谢。
【问题讨论】: