简体   繁体   中英

Issue with initbinder in spring 3

I have created one model class

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

now when I am trying to load this object using @ModelAttribute I am getting error

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

I konw I have to override @initBinder but how do I bind can any one please help me I am getting this error

I can not answer your question without knowing the exception, but there is an typo in your code that may cause an problem:

you have:

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

But I think it should be model attribute "customer" with an "r" at the end.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM