0

我正在使用 spring MVC 构建一个系统,现在我正在做*.jsp页面,我收到以下错误消息:

Invalid property 'flrequest' of bean class [se.lowdin.jetbroker.agent.mvc.FlightRequestBean]: Bean property 'flrequest' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

我已将此代码放在我的flightRequest.jsp中:

<tr>    
    <th>Departure Airport</th>
    <td><form:select path="flrequest" items="${airport}"/></td>         
</tr>
<tr>
    <th>Arrival Airport</th>
    <td><form:select path="flrequest" items="${airport}"/></td>
</tr>

我的 bean 看起来像这样:

public class FlightRequestBean {

    private Customer customer;
    private long id;
    private FlightStatus flightStatus;
    private long numberOfPassengers;
    private DateTime datetime;


    public void copyValuesToBean(FlightRequest request){

        setCustomer(request.getCustomer());
        setId(request.getId());
        setFlightStatus(request.getFlightStatus());
        setNumberOfPassengers(request.getNumberOfPassengers());
        setDatetime(request.getDatetime()); 

    }

    public void copyBeanToFlightRequest(FlightRequest request){

        request.setCustomer(getCustomer());
        request.setId(getId());
        request.setFlightStatus(getFlightStatus());
        request.setNumberOfPassengers(getNumberOfPassengers());
        request.setDatetime(getDatetime());

    }

    public Customer getCustomer() {
        return customer;
    }

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

    public long getId() {
        return id;
    }

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

    public long getNumberOfPassengers() {
        return numberOfPassengers;
    }

    public void setNumberOfPassengers(long numberOfPassengers) {
        this.numberOfPassengers = numberOfPassengers;
    }

    public DateTime getDatetime() {
        return datetime;
    }

    public void setDatetime(DateTime datetime) {
        this.datetime = datetime;
    }

    public FlightStatus getFlightStatus() {
        return flightStatus;
    }

    public void setFlightStatus(FlightStatus flightStatus) {
        this.flightStatus = flightStatus;
    }

}

我还有一个包含模拟机场的哈希图,我试图在我的表单中显示它:select。当我发现错误时。indexcontroller 持有的其他列表显示良好,但 hashmap 没有显示。

@Controller
public class IndexController {

    @Inject
    CustomerService customerService;

    @Inject
    FlightRequestService flightService;

    @Inject
    AirportService airportService;

    @RequestMapping("/index.html")
    public ModelAndView index() {

        List<FlightRequest> requests = flightService.getAllFlightRequest();
        List<Customer> customers = customerService.getAllCustomers();
        HashMap<Long, Airport>airport = airportService.getAllAirportCodes();

        ModelAndView mav = new ModelAndView("index");
        mav.addObject("flightRequests", requests);
        mav.addObject("customers", customers);
        mav.addObject("airportCodes", airport);

        return mav;
    }


}

最后我有了我的 flightRequest 控制器:

@Controller
@RequestMapping("/flightRequest/{id}.html")
public class FlightRequestController {

    @Inject 
    FlightRequestService service;

    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView index(@PathVariable long id) {


        FlightRequestBean bean = new FlightRequestBean();

        if (id > 0) {
            FlightRequest flrequest = service.getFlightRequest(id);
            bean.copyValuesToBean(flrequest);
        }


        ModelAndView mav = new ModelAndView("flightRequest");
        mav.addObject("flightRequestBean", bean);
        return mav;


    }

    @RequestMapping(method = RequestMethod.POST)
    public ModelAndView handleSubmit(FlightRequestBean bean) {


        if (bean.getId() > 0) {
            FlightRequest flrequest = service.getFlightRequest(bean.getId());
            bean.copyBeanToFlightRequest(flrequest);
            service.updateFlightRequest(flrequest);
        } else {
            FlightRequest flrequest = new FlightRequest();
            bean.copyValuesToBean(flrequest);
            service.createFlightRequest(flrequest);
        }

        return new ModelAndView("redirect:/index.html");
    }



}

因此,某处存在导致该错误消息的问题。有谁知道这个问题的原因是什么?错误消息说明了无效的 getter 和 setter?但是怎么可能,因为我使用的是哈希图而不是

4

1 回答 1

1

FlightRequestBean应该具有具有flrequest适当 getter 和 setter 的属性。您选择的值需要存储在某个地方。

于 2013-09-19T09:49:49.757 回答