私はCustomerDTOを使用しています:
public class CustomerDTO {
private int customerId;
private String customerName;
private String customerAddress;
public int getCustomerId() {
return customerId;
}
public void setCustomerId(int customerId) {
this.customerId = customerId;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getCustomerAddress() {
return customerAddress;
}
public void setCustomerAddress(String customerAddress) {
this.customerAddress = customerAddress;
}
}
次に、customerId に基づいて顧客をフェッチする CustomerDAO を使用しています。
public class CustomerDAO {
private CustomerDTO customer;
public void setCustomer(CustomerDTO customer) {
this.customer = customer;
}
public CustomerDTO getCustomer(int customerId){
try{
if("you get customer based on customer id") then "return the customer";
}catch(Exception ex){
return new CustomerDTO();
//some other work
}
}
}
にアクセスしようとするとnew CustomerDTO();
、CustomerDAO のこのコードが表示されます。フィールドをデフォルト値で初期化することを考えています。null
new CustomerDTO().getCustomerName()
Spring フレームワークの有無にかかわらず、どうすればこれを達成できますか?