//从基本图书表,填加单本到包月图书表(多本)
function addMore(){
var checkedNum = $("input[id^='specialListIds']:checked").length;
if(checkedNum == 0){
alert("请选择要添加的记录!");
return;
}
if (confirm("确定要添加选定"+ checkedNum + "的记录?")) {
$.ajax({
type : "post",
url: "<%=request.getContextPath()%>/admin/booktypemonthly/addBooks.do",
data: $("#addBookTypeBookListForm").serialize(),
dataType:'json',
beforeSend:function(XMLHttpRequest){
$("#loading").show();
},
success: function (data) {
$("#loading").hide();
if(data.success){
nextPage('${bookType.page.currentPage}');
}else{
alert("添加失败!");
}
}
});
}
}
--------------------------------后台 --------------------------------
//批量添加
@RequestMapping(value="/addBooks")
public void partnerCategoryDelPost(HttpServletResponse response,@RequestParam("specialListIds") long[] ids,@modelattribute("book")Book entity){
JSONObject json=new JSONObject();
response.setContentType("text/html;charset=utf-8");
boolean re = true;
try {
if(ids != null && ids.length > 0){
for (long id : ids) {
entity.setBookId(String.valueOf(id));
bookTypeService.addBookTypeMonthlyBookFromBaseBook(entity);
}
}
} catch (Exception e) {
re = false;
e.printStackTrace();
}finally{
if(re){
json.put("success",true);
json.put("message","全部保存成功");
} else {
json.put("success",false);
}
try {
response.getWriter().print(json.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
注意:表单中有附件上传的时候,不能用ajax方式,用form.submit()方式