1

So i have the following problem. I have a controller which i mapped to "/reservationQuery/*". Whenerver i go on the url for "delete_1" method, it works, but whnever i try and go on the "delete_2" method it says that there was no mapping for that URI. But why does that happen? Shouldn all URI beggining with /reservationQuery/ be mapped by my ReservationQueryController?

And if i want to use the second URI for deletion, do i have to make another controller and map it to /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";
}




}
2
  • Can you print the whole URL Commented Aug 14, 2014 at 8:05
  • I think you should be using a RequestMapping at the class level and Paths at the method level with the path appending extra onto the original URL defined in the RequestMapping. Commented Aug 14, 2014 at 8:11

2 Answers 2

3

You can remove the extra value of "reservationQuery" in the method level as you have already mapped "reservationQuery" in the Controller, which is the class level.

So what's happening is that at delete your URL is going to begin with /reservationQuery/reservationQuery/.

I think that's the reason for an error and it should be HTTP Error 404

Sign up to request clarification or add additional context in comments.

Comments

2

You should map your controller with "/reservationQuery" and your method delete_1 should be mapped with "/{reservationID}" and method delete_2 should be mapped with "/delete/{reservationID}". There is no need to repeat controller mapping in methods.

1 Comment

IMHO, it is a neater solution than the one proposed by jorrin, because you factorize the upper part of the URL at controller level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.