This article mainly introduces how jquery transfers an array into a string to the server for processing. If you need it, refer to jquery to convert the array into a string and then upload it to the server (after jquery converts the array into a string, format: 1, 2, 3, speed, rewr)
The Code is as follows:
Define (function (require, exports, module ){
Var every Y = require ('common/bootstrap-every y ');
Module. exports = function ($ element ){
$ Element. on ('click', '[data-role = batch-delete]', function (){
Var $ btn = $ (this );
Name = $ btn. data ('name ');
Var ids = [];
$ Element. find ('[data-role = batch-item]: checked'). each (function (){
Ids. push (this. value );
});
If (ids. length = 0 ){
Using Y. danger ('unspecified' + name );
Return;
}
If (! Confirm ('Do you want to delete the selected '+ ids. length +' bar '+ name +? ')){
Return;
}
$ Element. find ('. btn'). addClass ('Disabled ');
Policy.info ('deleting '+ name +', please wait. ', 60 );
Var values = ids. toString ();
$. Post ($ btn. data ('url'), {ids: values}, function (){
Window. location. reload ();
});
});
};
});
Receives the string passed by jquery, parses it into an array, and converts it to a list set.
The Code is as follows:
/**
* Batch Delete private messages.
*/
@ RequestMapping (value = "/delete", method = {RequestMethod. GET, RequestMethod. POST })
Public ResponseEntity delete (HttpServletRequest request ){
// List of private message IDs to be deleted
String messageIds = ServletRequestUtils. getStringParameter (request, "ids ","");
String [] messageList = messageIds. toString (). split (",");
List MessageIdList = Arrays. asList (messageList); // convert the array to list
Logger.info ("------------" + messageIds );
Logger.info ("------------" + messageList [0]);
Try {
Boolean opStatus = messageManager. delete (messageIdList );
Logger.info ("delete private message: opStatus ={}", opStatus );
Return this. okResponse (opStatus );
} Catch (Exception e ){
Logger. error ("exception occurred when adding a private message, Cause:", e );
Return this. errorResponse (e. getMessage ());
}
}