我正在使用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>
我的豆子看起来像这样:
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;
}
}
我还有一个包含模拟机场的哈希地图,我试图以形式显示它:选择。当我和错误。索引控制器持有的其他列表显示得很好但是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?但是,因为我使用的是散列图而不是
,所以它是怎么回事答案 0 :(得分:0)
您的FlightRequestBean
应该有一个属性flrequest
,并带有相应的getter和setter。您选择的值需要存储在某处。