Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Required String parameter is not present Spring MVC

I want to access two different pages in my browser using:

http://localhost:8080/name?views

and

http://localhost:8080/name?uviews

But I'm getting error Required String parameter 'uviews' is not present when I use first url and I get Required String parameter 'views' is not present when I use second one.

here is my Response body

@ResponseBody     
public Object getViewInJson(@RequestParam("views") String views ,@RequestParam("uviews") String uviews) throws IOException{

 loader = new AnalyticsLoader();



    return loader.AnalyticsLoader(views,uviews);
}

How can access both views and uviews?

like image 945
LeTadas Avatar asked Sep 20 '16 08:09

LeTadas


3 Answers

Add required=false attribute to @RequestParam..Change to

@RequestParam(required=false,name="views") String view,..
like image 149
Prasanna Kumar H A Avatar answered Nov 17 '22 08:11

Prasanna Kumar H A


Add required=false to the @RequestParam notation for both. Or you could decide to explicitly use one, set it to required=false and set the other as the defaultValue.

See the documentation for further information.

like image 39
ChiefTwoPencils Avatar answered Nov 17 '22 09:11

ChiefTwoPencils


I was using Postman for API hit, Adding required=false and defalutValue might be helpful, but required=false results in NULL Exception. Then I have Removed the Headers (can Authorization header) in Postman and its works.

like image 1
Romil Patel Avatar answered Nov 17 '22 07:11

Romil Patel