Hello,
I was just wondering if there is an easier way to handle the case when required parameters are not passed to the Controller.
Say I have a method in my (address) controller
So if someone tries to access the site - this wayCode:public String showBuyItNow(@RequestParam("order") Integer orderId, WebRequest request, Map<String, Object> model) { }
1) http://localhost/address
I get an error saying that "Required java.lang.Integer parameter 'order' is not present"
2) And if someone accesses it this way
http://localhost/address?order
I get an error saying java.lang.IllegalArgumentException: id to load is required for loading
The way I have handled the first case, is to explicitly mark even required attributes as false.
The way I'm handling the second case is by explicitly checking if orderId==null - then send to error page.Code:public String showBuyItNow(@RequestParam(value = "order", required = false) Integer orderId, WebRequest request, Map<String, Object> model)
For both these cases is there a better way to handle it in Spring.
Appreciate your help....
Thanks


Reply With Quote