jquery把陣列變成字串然後傳到服務端(jquery把陣列轉換成字串後,格式如1,2,3,速度,rewr)
define(function(require, exports, module) {
var Notify = require('common/bootp-notnify' ;
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) {
Notify.danger('未選取任何' name);
return ;
}
if (!confirm('這的要刪除選取的' ids.length '條' name '嗎? .info('正在刪除' name ',請稍等。', 60);
var values=ids.toString();
$.post($btn.data('url'), {ids :values}, function(){
window.location.reload();
});
});
};
}) ;
接收jquery傳過來的字串,並解析成數組,再把數組轉換成list集合
複製程式碼
/**
* 批次刪除私訊。
*/
@RequestMapping(value = "/delete", method = {RequestMethod.GET,RequestMethod.POST} )
public ResponseEntity
delete(HttpServletRequest request) {
// 待刪除的私訊ID列表
String messageIds = ServletRequestUtils.getString,Parameter(request, "String messageIds = ServletRequestUtils.getString,Parameter(request, "idameter" [] messageList=messageIds.toString().split(",");
List messageIdList = Arrays.asList(messageList);//陣列轉換成list
logger.info("--- ---------" messageIds);
logger.info("------------" messageList[0]);
try {
boolean opStatus = messageManager.delete(messageIdList);
logger.info("刪除私訊:opStatus={}", opStatus);
return this.okResponse(opStatus);
} catch (Exception e) {
logger.error("添加私訊時發生異常, Cause: ", e);
return this.errorResponse(e.getMessage());
}
}