Jsp SpringMVC无法读取Bean属性
我正在使用SpringMVC构建一个系统,现在我正在执行Jsp SpringMVC无法读取Bean属性,jsp,spring-mvc,java-ee-5,Jsp,Spring Mvc,Java Ee 5,我正在使用SpringMVC构建一个系统,现在我正在执行*.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 gette
*.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>
我还有一个hashmap,其中包含模拟机场,我正试图在我的表单中显示它: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;
}
}
因此,在某个地方出现了导致错误消息的问题。有人知道问题的原因吗?
错误消息说明无效的getter和setter?但是这怎么可能呢,因为我使用的是hashmap,而不是你的
FlightRequestBean
应该有一个属性flrequest
,带有适当的getter和setter。您选择的值需要存储在某个位置
@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;
}
}
@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");
}
}