650) this.width=650; "src=" Http://img.mp.itc.cn/upload/20160613/bdcd67d3f36842edbdfb604425468b0f_th.jpg "style=" border:0px;margin:0px;padding:0px;font-size:0px; "/>
recent projects need to do a batch deletion of the function, delete conditions have multiple, need to pass from the page to the background server program, a single delete, you can stitch parameters to the URL, the server side to get parameters after the delete operation can be done. But the bulk of the deletion, parameters will be many, the delivery of some trouble. Of course there is a more common solution, is the use of commas, underscores, or semi-colon segmentation, and then to the background of the split before the operation, this method requires the foreground splicing, background parsing, slightly more complicated and error prone. For the Java program, I do not seem very object-oriented. So it's natural to think of the use of JSON string to pass data, the following steps:1, the first to pass the parameters to be encapsulated into a JS object, the code sample is as follows:
var params = [];
var param = {};
Param["AAA"] = "a";
param["BBB"] = true;
param["CCC"] = 2;
Params.push (param);
2, next to the JS object into a JSON string, the more common practice is to use JSON.STRINGFY (), after trying to find that IE8 browser does not support (this method for Google, Firefox, and IE9 browser version above the perfect support), and our current products only support IE browser, Turn to help Google Baidu, find a more general JS method, the code is as follows:
function Obj2str (obj) {
Switch (typeof (obj)) {
Case ' object ':
var ret = [];
if (obj instanceof Array) {
for (var i = 0, len = obj.length; i < Len; i++)
{
Ret.push (Obj2str (obj[i));
}
Return ' [' + ret.join (', ') + '] ';
}
else if (obj instanceof RegExp)
{
return obj.tostring ();
}
Else
{
For (var a in obj)
{
Ret.push (A + ': ' + obj2str (Obj[a]));
}
Return ' {' + ret.join (', ') + '} ';
}
Case ' function ':
Return ' function () {} ';
Case ' number ':
return obj.tostring ();
Case ' string ':
Return ' "' + obj.replace (/(\\|\")/g, ' \\$1 '). Replace (/\n|\r|\t/g, function (a)
{
return (' \ n ' = = a)? ' \\n ': (' \ r ' = = a)? ' \\r ': (' \ t ' = = a)? ' \\t ': ';
}) + ' "';
Case ' Boolean ':
return obj.tostring ();
Default
return obj.tostring ();
}
}
3, the front-end package, the use of Ajax request to the background, Java parsing JSON string method, you can find a good way to write on the internet, Of course, you can also use Json-lib-xxx.jar, the jar package is widely used in the project, LZ, a company used it to do a lot of JSON conversion work, using the following methods:
Jsonarray Jsonarray = Jsonarray.fromobject (JSONSTR);
List<map> cmdlist = (list<map>) jsonarray.tocollection (Jsonarray, Map.class);
4, through the built-in method into a collection, and then passed to Ibatis or their own use of the database persistence layer processing can be.
This article from the "11247808" blog, reproduced please contact the author!
Javaweb front end sends objects to server side