I want to trigger 404 page whenever I wasn't passed all of the parameters. Lets say I have the following URI:
/myapp/op?param1=1¶m2=2@param3=3
In case on of the parameters wasn;t invoked I want to return 404 page. I tried doing:
@ResponseStatus(HttpStatus.NOT_FOUND)
@RequestMapping(value = "op", params = { "!param1" })
public void missingArg() {
}
but then I get an exception telling me there is ambiguity between methods that handle missing second and third parameter.
How can I accomplish this, then?
Best Answer
If you're using Spring 3.1 you can define an exception class like so:
Now whenever you throw that exception, Spring will return the http status defined in your
@ResponseStatus
annotation. For example:will return a
404
wheneverparam1
orparam2
is null.