对生成的值使用getter方法。好还是坏?

时间:2016-11-29 00:09:24

标签: java methods wicket el getter

好的,我知道我可以这样做,因为我之前看到过它。

基本上,我在我的一个类中创建一个getter方法,使得该方法没有关联的类变量。

例如

@Entity
public class Customer implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue
private Integer customerID;

@NaturalId
private String name;

@OneToMany(mappedBy = "customerID", cascade = CascadeType.ALL, orphanRemoval = true)
private List<CustomerAddress> customerAddressList;
.
.
.
public CustomerAddress getMainAddress(){
    //Calculations to retrieve the customer's main/default/primary address
    //from the List, customerAddressList.
}

虽然我没有在Thymeleaf中尝试过这个(但是打算尽快这样做),但我知道在Wicket中我可以使用属性表达式来访问客户的主要地址(我认为这很有趣,因为没有变量在Customer类中调用mainAddress

话虽如此,这种吸气剂的使用被认为是可接受的做法

0 个答案:

没有答案
相关问题