2013年9月4日星期三

spring mvc receives an array of objects

Encountered in the development of this demand , the need to receive an array of objects in the background to add . such as adding detailed information . Will the background spring mvc how to receive an array of objects , the front desk or easyUI via ajax request form form data can be submitted .
------ Solution ---------------------------------------- ----
input of the name are the same, in the background , with the

String [] names = request.getParameterValues ​​("name") ;/ / name
String [] moneys = request.getParameterValues ​​("money") ;/ / password
..... N lines , N = number of attributes in the object

then write a for loop to cycle in accordance with one of the array ,
for (int i = 0; i first new object, and then once the assignment according to the attribute of these properties and the array is the same order of reception
}
------ Solution ----------------------------------- ---------
the array packaged

For example, you want to receive a Bank of type array, then build a first class
class BankArray {
private Bank banks [];

public void setBanks (Bank [] banks) {
this.banks = banks;
}

public Bank [] getBanks () {
return banks;
}
}

/ / used as a parameter BankArray
@ RequestMapping (value = "xxx", method = RequestMethod.POST)
public ModelAndView doLogOut (BankArray param) {}

/ * page in the following way * /








------ For reference only ------ ---------------------------------
the first floor has been tested . The second floor of this method is the answer I wanted , it should also be , no testing, but my form is dynamically added , so death is not enough to write ,
------ For reference only - -------------------------------------
dynamically added generally accompanied by dynamic deleted if id per times are +1 , then increase after deleting a few times , id likely not continuous.
------ For reference only -------------------------------------- -
the knot posted . . .
------ For reference only -------------------------------------- -

element is dynamic, your js is dynamic, meaning that the name attribute should submit an assignment rather than an increase in the time when the assignment ,




...
$ ("input [id = name]"). each (function (n, d) {
this.name = "name [" + n + "]";
});
form.submit () or $. ajax
------ For reference only ---------------------- -----------------

element is dynamic, your js is dynamic, meaning that the name attribute should submit the assignment and the time when the assignment is not increasing ,   
  
  
  
  
...   
$ ("input [id = name]"). each (function (n, d) {   
this.name = "name [" + n + "]";   
});   
form.submit () or $. ajax  


There is no complete code , thank

没有评论:

发表评论