You cannot instantiate an error by using the List<bean> report directly on the method!
List<bean> must be placed in an object to be accepted as a property. See the example below for details
Front-end Code
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "UTF-8"> <title>Page</title></Head><Body><H1>Array Pass parameter test</H1><Scriptsrc= "/webpagetest/js/jquery-2.0.3.min.js"></Script><Scripttype= "Text/javascript"> functionTest () {$.ajax ({URL:'/webpagetest/pagedata', data:{'ID':1, 'Order[0].column':'name', 'Order[0].dir':'ASC', 'Order[1].column':'Phone', 'Order[1].dir':'desc'}, Success:function(RT) {alert (RT); }, Error:function() {alert ('Error'); } }); } functiontest2 () {$.ajax ({URL:'/webpagetest/pagedata2', data:{'ID':1, 'Order[0][column]':'name', 'Order[0][dir]':'ASC', 'Order[1][column]':'Phone', 'Order[1][dir]':'desc'}, Success:function(RT) {alert (RT); }, Error:function() {alert ('Error'); } }); }</Script><Buttononclick= "Test ()">Test</Button><Buttononclick= "test2 ()">Test 2</Button></Body></HTML>
Background code
@RequestMapping ("/pagedata") @ResponseBody PublicString Index (@RequestParam (value= "Order[0].column", required =false) String Order0column, httpservletrequest request, Myvo vo) {Syst Em.out.println ("Get a single parameter:"); System.out.println (Order0column); System.out.println ("Get All Parameters:"); Map<String,String[]> params =Request.getparametermap (); for(map.entry<string,string[]>Entry:params.entrySet ()) {System.out.println ("Key:" +entry.getkey () + "value:" +arrays.aslist (Entry.getvalue ())); } System.out.println ("Get Vo"); System.out.println ("ID:" +Vo.getid ()); System.out.println ("Orders:"); for(Order o:vo.getorder ()) {System.out.println ("Column:" + o.getcolumn () + "dir:" +O.getdir ()); } return"OK"; } @RequestMapping ("/pagedata2") @ResponseBody PublicString Index (@RequestParam (value= "order[0][column]", required =false) String Order0column, httpservletrequest request/*, MyVO2 VO2*/) {System.out.println ("Get a single parameter:"); System.out.println (Order0column); System.out.println ("Get All Parameters:"); Map<String,String[]> params =Request.getparametermap (); for(map.entry<string,string[]>Entry:params.entrySet ()) {System.out.println ("Key:" +entry.getkey () + "value:" +arrays.aslist (Entry.getvalue ())); }//System.out.println ("Get VO2");//System.out.println ("ID:" +vo2.getid ());//System.out.println ("Orders:");//For (list<string> O:vo2.getorder ()) {//System.out.println ("column:" + o.get (0) + "dir:" +o.get (1));// } return"OK"; }
Two entity object (must be a class in a separate file, otherwise the constructor's error cannot be reported)
Public classmyvo{Private intID; PrivateList<order> Order =NewArraylist<order>(); Public intgetId () {returnID; } Public voidSetId (intID) { This. ID =ID; } PublicList<order>GetOrder () {returnorder; } Public voidSetorder (list<order>order) { This. Order =order; }}
Public classorder{PrivateString column; PrivateString dir; PublicString GetColumn () {returncolumn; } Public voidsetcolumn (String column) { This. Column =column; } PublicString Getdir () {returndir; } Public voidSetdir (String dir) { This. Dir =dir; }}
SPRINGMVC receive Array type parameters