2012-12-09 119 views
0

我已經創建了一個模型類問題與春季initbinder 3

@Entity 
@Table(name = "tblcoustomer") 
public class Customer { 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "tblcoustomer_cid_gen") 
    @SequenceGenerator(name = "tblcoustomer_cid_gen", sequenceName = "tblcoustomer_cid_seq") 
    @Column(name = "cid") 
    private int id; 

    @ManyToOne(targetEntity = FinancialMonth.class, fetch = FetchType.EAGER) 
    @JoinColumn(name = "monthId", nullable = false) 
    private FinancialMonth monthId; 

    @ManyToOne(targetEntity = Company.class, fetch = FetchType.EAGER) 
    @JoinColumn(name = "companyId", nullable = false) 
    private Company companyId; 

    @ManyToOne(targetEntity = CustomerType.class, fetch = FetchType.EAGER) 
    @JoinColumn(name = "customerType", nullable = false) 
    private CustomerType customerType; 

    private String firstName; 
    private String lastName; 
    private String gender; 
    private int age; 
    private String designation; 

    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public FinancialMonth getMonthId() { 
     return monthId; 
    } 

    public void setMonthId(FinancialMonth monthId) { 
     this.monthId = monthId; 
    } 

    public Company getCompanyId() { 
     return companyId; 
    } 

    public void setCompanyId(Company companyId) { 
     this.companyId = companyId; 
    } 

    public CustomerType getCustomerType() { 
     return customerType; 
    } 

    public void setCustomerType(CustomerType customerType) { 
     this.customerType = customerType; 
    } 

    public String getFirstName() { 
     return firstName; 
    } 

    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 

    public String getLastName() { 
     return lastName; 
    } 

    public void setLastName(String lastName) { 
     this.lastName = lastName; 
    } 

    public String getGender() { 
     return gender; 
    } 

    public void setGender(String gender) { 
     this.gender = gender; 
    } 

    public int getAge() { 
     return age; 
    } 

    public void setAge(int age) { 
     this.age = age; 
    } 

    public String getDesignation() { 
     return designation; 
    } 

    public void setDesignation(String designation) { 
     this.designation = designation; 
    } 
} 
現在

當我嘗試使用@ModelAttribute我收到錯誤

@RequestMapping(value = "/saveCustomer") 
public ModelAndView addUser(HttpServletRequest request, 
     @ModelAttribute("custome") Customer customer) { 
    Map<String, Object> model = new HashMap<String, Object>(); 
    return new ModelAndView("addCustomer", model); 
} 

我konw我要重寫加載此對象@initBinder,但我怎麼綁定可以任何人請幫助我我得到這個錯誤

+0

你正在得到什麼錯誤? : - 另請注意,表單bean對象的默認名稱是''command「',所以請將'<形式:表單'聲明與相應的'commandName'或'modelAttribute'值添加到問題中。 –

+0

@Deepak庫馬爾:請你發佈例外。 – Ralph

回答

0

我不能在不知道例外的情況下回答你的問題,但是你的代碼中有一個錯字可能會導致瑟的問題:

您有:

public ModelAndView addUser(HttpServletRequest request, 
    @ModelAttribute("custome") Customer customer) 

但我認爲這應該是模型屬性「客戶」與「R」結尾。

public ModelAndView addUser(HttpServletRequest request, 
    @ModelAttribute("customer") Customer customer)