Pardon me for asking such a simple question here as I'm new to Spring MVC 3.0. I have been reading the documentation from spring source website a few times. Here's a code snippet that I'll refer to for my question below:-
@RequestMapping("/pets/{petId}")
public void findPet(@PathVariable String petId, Model model) {
// implementation omitted
}
If I intend to use the URI template based on this example, is it always preferable to set up the @PathVariable type to be String even though I'm expecting it to be other type, such as, an int? The documentation says the @PathVariable annotation can be of any simple type, but if Spring is unable to convert the invalid petId into an int (for example, user enters some characters instead of numbers), it will throw a TypeMismatchException.
So, when does the validator comes into play? Do I leave all the @PathVariable types to be String and have the validator to perform the validation on the String values, and if there's no validation error, then explicitly convert the String to the desired type?
Thank you.