Excuse me for asking such a simple question, as I am new to Spring MVC 3.0. I have read the documentation from the Spring website several times. Here is a snippet of code that I will discuss below: -
@RequestMapping("/pets/{petId}") public void findPet(@PathVariable String petId, Model model) {
If I intend to use a URI pattern based on this example, it is always preferable that the @PathVariable type be String, although I expect it to be a different type, such as int? The documentation says that the @PathVariable annotation can be of any simple type, but if Spring cannot convert the invalid petId to int (for example, the user enters some characters instead of numbers), it will throw a TypeMismatchException.
So when is the validator valid? Should I leave all @PathVariable String types and have a validator to check for String values, and if there is no validation error, will it explicitly convert String to the desired type?
Thanks.
java spring spring-mvc
limc
source share