初始化程序在春季3中出现问题

时间:2012-12-09 07:50:18

标签: java spring hibernate spring-mvc

我创建了一个模型类

@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);
}

我知道我必须覆盖@initBinder但是如何绑定任何一个请帮助我我收到此错误

1 个答案:

答案 0 :(得分:0)

我不能在不知道异常的情况下回答您的问题,但您的代码中存在可能导致问题的拼写错误:

你有:

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

但我认为它应该是模型属性“customer”,最后带有“r”。

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