这是我的对象类:
public class Address
{
public final String line1;
public final String town;
public final String postcode;
public Address(final String line1, final String town, final String postcode)
{
this.line1 = line1;
this.town = town;
this.postcode = postcode;
}
}
我将它添加到速度上下文中,如下所示:
Address theAddress = new Address("123 Fake St", "Springfield", "SP123");
context.put("TheAddress", theAddress);
但是,在编写模板时,以下内容不会呈现地址字段(但是,当我将 getter 添加到 Address 类时它可以正常工作)
<Address>
<Line1>${TheAddress.line1}</Line1>
<Town>${TheAddress.town}</Town>
<Postcode>${TheAddress.postcode}</Postcode>
</Address>
是否可以在不添加 getter 的情况下从 Velocity 访问对象上的公共字段?