我为表单开发了两个方法,另一个用于修改预留。将显示一条消息和一条错误消息:"必需的整数参数' id'不在场。请问你能帮帮我吗 我的控制器是:
@Controller
@RequestMapping("/reservations")
public class ReservationController {
@Autowired
ReservationService reservationService;
@Autowired
private UserService userService;
@Autowired
ClassroomService classroomService;
@RequestMapping(value = "/updatereservationForm", method = RequestMethod.GET)
public ModelAndView UdateReservationSalle(@RequestParam(value="id",
required = true) Integer id, ModelMap model) {
Reservation reservation = reservationService.findById(id) ;
model.addAttribute("reservation", reservation);
List <Classroom> classrooms = classroomService.getAll();
model.addAttribute("classrooms", classrooms);
List <User> users = userService.getAll();
model.addAttribute("users", users);
return new ModelAndView("reservation/updateResR", model);
}
@RequestMapping("/updateReservation")
public ModelAndView updateResR(@RequestParam("id") Integer id,ModelMap
model) {
Reservation reservation=reservationService.findById(id);
model.addAttribute("reservation",reservation);
return new ModelAndView("updateResR",model);
}
@RequestMapping("/updateReservationRInput")
public ModelAndView updateReservationRInput
(@RequestParam("id") Integer id,
@RequestParam(name="roomid",defaultValue="-1") Integer roomid,
@RequestParam("datebegin") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
Date datebegin,@RequestParam("dateend")
@DateTimeFormat(pattern =
"yyyy-MM-dd HH:mm") Date dateend,
Integer userid,RedirectAttributes redirectAttributes, ModelMap model)
Reservation reservation = reservationService.findById(id);
Classroom classroom = classroomService.findById(roomid);
User user = userService.findById(userid);
reservation.setClassroom(classroom);
reservation.setUser(user);
reservation.setDateBegin(datebegin);
reservation.setDateEnd(dateend);
return testReservation(roomid, datebegin, dateend,
redirectAttributes,reservation);
}
我的页面JSP是:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="security" %>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Gestion des réservation</title>
</head>
<body>
<form method=GET action="/reservations/updateReservationRInput">
Salles : <select name="roomid">
<option value=""></option>
<c:forEach items="${classrooms}" var="classroom">
<c:if test="${reservation.classroom.id==classroom.id}">
<option value="${classroom.id}" selected="selected">${classroom.name}</option>
</c:if>
<c:if test="${reservation.classroom.id!=classroom.id}">
<option value="${classroom.id}">${classroom.name}</option>
</c:if>
</c:forEach></select>
Date Debut : <input type="datetime-local" name="datebegin"
value=<fmt:formatDate pattern="yyyy-MM-dd HH:mm"
value="${reservation.datebegin}"/>>
DateFin : <input type="datetime-local" name="dateend"
value=<fmt:formatDate pattern="yyyy-MM-dd HH:mm"
value="${reservation.dateend}"/>>
user Id: <input name="id" value="${reservation.id}" type="hidden" />
<select name="userid">
<option value=""></option>
<c:forEach items="${users}" var="user">
<c:if test="${reservation.user.id==user.id}">
<option value="${user.id}" selected="selected">${user.name} ${user.surname}</option>
</c:if>
<c:if test="${reservation.user.id!=user.id}">
<option value="${user.id}">${user.name} ${user.surname}</option>
</c:if>
</c:forEach>
</select>
<input type="submit" value="Modify" />
</form>
</body>
</html>
&#13;