spring - setting multiple request parameter Optional -
i stuck in big problem want ignore attributes of object not know how skip multiple attributes same request object
here code
testrequestinfo.java
public class testrequestinfo extends basefilter { private string id; public string getid() { return id; } public void setid(string id) { this.id = id; } }
basefilter.java
public class basefilter { private paginginfo paging; public paginginfo getpaging() { return paging; } public void setpaging(paginginfo paging) { this.paging = paging; } }
paginginfo.java
@xmlrootelement(name = "paging") public class paginginfo { private integer totalnumofrows; private integer minrownumber; private integer maxrownumber; public paginginfo() { super(); } public paginginfo(integer totalnumofrows, integer maxrownumber, integer minrownumber) { super(); this.totalnumofrows = totalnumofrows; this.maxrownumber = maxrownumber; this.minrownumber = minrownumber; } public paginginfo(integer maxrownumber, integer minrownumber) { super(); this.maxrownumber = maxrownumber; this.minrownumber = minrownumber; } public integer gettotalnumofrows() { return totalnumofrows; } public void settotalnumofrows(integer totalnumofrows) { this.totalnumofrows = totalnumofrows; } public integer getminrownumber() { return minrownumber; } public void setminrownumber(integer minrownumber) { this.minrownumber = minrownumber; } public integer getmaxrownumber() { return maxrownumber; } public void setmaxrownumber(integer maxrownumber) { this.maxrownumber = maxrownumber; } }
controller
@requestmapping(value = { "/testlist"} , method=requestmethod.get, produces = mediatype.application_json_value) public @responsebody string testlist(httpservletrequest request, testrequestinfo testrequestinfo) { .... .... }
request made
http://example/abc/testlist?id=&paging.maxrownumber=&paging.minrownumber=
on blank attribute request made bad request , gives error 400
, if populate these parameters, gives proper response.
@requestparam(value = "i", required=false)
works singly entity how can make minrownumber
, maxrownumber
optional?
thanks in advance
here code , test.
> http://localhost:8080/fileupload/testlist.htm?id=1&paging.maxrownumber=1&paging.minrownumber=1 > testrequestinfo [id=1, getpaging()=paginginfo [totalnumofrows=null, > minrownumber=1, maxrownumber=1]] > > http://localhost:8080/fileupload/testlist.htm?id=1&paging.maxrownumber=1&paging.minrownumber= > testrequestinfo [id=1, getpaging()=paginginfo [totalnumofrows=null, > minrownumber=null, maxrownumber=1]] > > http://localhost:8080/fileupload/testlist.htm?id=1&paging.maxrownumber=&paging.minrownumber= > testrequestinfo [id=1, getpaging()=paginginfo [totalnumofrows=null, > minrownumber=null, maxrownumber=null]] @requestmapping(value = { "/testlist"} , method=requestmethod.get) public @responsebody string testlist(httpservletrequest request, testrequestinfo testrequestinfo) { system.out.println(testrequestinfo); return "ss"; }
my spring config
<servlet> <servlet-name>mvc-dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherservlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvc-dispatcher</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping>
as can see code functional, seems problem url-pattern using.
check using
<mvc:annotation-driven/>
Comments
Post a Comment