所以我有以下问题。我有一个映射到“ / reservationQuery / *”的控制器。每当我使用“ delete_1”方法的url时,它都起作用,但是无论何时我尝试使用“ delete_2”方法,它都说该URI没有映射。但是为什么会这样呢?我的ReservationQueryController是否应该映射所有以/ reservationQuery /开头的URI?
而且,如果我想使用第二个URI进行删除,是否需要制作另一个控制器并将其映射到/ reservationQuery / delete / *?
@Controller
@RequestMapping("/reservationQuery/*")
public class ReservationQueryController{
private ReservationService reservationService;
@Autowired
public ReservationQueryController(ReservationService reservationService) {
this.reservationService = reservationService;
}
@RequestMapping(value="/reservationQuery/{reservationID}", method=RequestMethod.GET)
public String delete_1(@PathVariable("reservationID") int reservationID, Model model){
reservationService.deleteReservation(reservationID);
return "reservationQuery";
}
@RequestMapping(value="/reservationQuery/delete/{reservationID}", method=RequestMethod.GET)
public String delete_2(@PathVariable("reservationID") int reservationID, Model model){
reservationService.deleteReservation(reservationID);
return "reservationQuery";
}
}
最佳答案
您可以在方法级别中删除“ reservationQuery”的额外值,因为您已经在控制器(类级别)中映射了“ reservationQuery”。
因此,发生的事情是在删除时,您的URL将以/ reservationQuery / reservationQuery /开头。
我认为这是错误的原因,应该是HTTP错误404
关于java - 路径变量未映射Spring MVC,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25302797/