在bean中插入数据时出错

时间:2013-06-14 05:50:41

标签: hibernate jsp spring-mvc jstl

我正在尝试在包含以下字段的表中插入数据: id PK, cid FK, pid FK,

我正在尝试在此订单bean中插入数据。

这是我的JSP代码:

<form:form>
    <form:hidden path="id"/>
    <table cellpadding="2px">
    <tr><td><label>Customer ID</label></td><td><form:input path="cid"/><form:errors   path="cid" /></td></tr>
    <tr><td><label>Package ID</label></td><td><form:input path="pid"/><form:errors     path="pid" /></td></tr>      
    <tr align="center"><td colspan="2"><input type="submit" value="Save Changes"     /></td></tr>
    </table>
</form:form>

,这是控制器代码:

@RequestMapping(value="/editorder", method=RequestMethod.GET)
        public String EditPerson(Model model){
            model.addAttribute("command", new Order());     
            return "/WEB-INF/pages/orders/editorder.jsp";
        }

我收到错误:(我在此仅提到根本原因)

根本原因 org.springframework.beans.NotReadablePropertyException:bean类[com.order.domain.Order]的属性'cid'无效:Bean属性'cid'不可读或getter方法无效:getter的返回类型是否匹配setter的参数类型?

有任何解决方案吗?

Here is Order bean:
package com.order.domain;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="orders")
public class Order extends BaseEntity{

    @ManyToOne
    @JoinColumn(name="cid")
    private Customer customer;

    @ManyToOne
    @JoinColumn(name="pid")
    private Packagee package1;

    @OneToMany(mappedBy="order")
    private List<Feedback> feedbacks;

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Packagee getPackage1() {
        return package1;
    }

    public void setPackage1(Packagee package1) {
        this.package1 = package1;
    }

    public List<Feedback> getFeedbacks() {
        return feedbacks;
    }

    public void setFeedbacks(List<Feedback> feedbacks) {
        this.feedbacks = feedbacks;
    }
    } 

1 个答案:

答案 0 :(得分:0)

错误消息显示:

  

bean类[com.order.domain.Order]的属性'cid'无效:Bean属性'cid'不可读或具有无效的getter方法

因此,Spring正在为cid课程中的属性com.order.domain.Order寻找一个getter:

public Long getCid() {
    ...
}

你班上没有这样的吸气剂。