在 ItemController 上:
@RequestMapping(value="/delete.htm", produces="application/json", method=RequestMethod.POST)
public @ResponseBody Item deleteItem(
@RequestParam String itemName) {
Item existingItem = new Item();
existingItem.setItemName(itemName);
itemService.deleteItem(existingItem);
return existingItem;
}
在 ItemDao 实现上:
@Override
public void deleteItem(Item item) {
// TODO Auto-generated method stub
sessionFactory.getCurrentSession().delete(item);
}
在项目 ServiceImpl 上:
@Transactional
public void deleteItem(Item item) {
// TODO Auto-generated method stub
itemDao.deleteItem(item);
}
在 Jquery Grid 上,我正在使用删除功能:
function deleteRow(obj, args) {
// Get the currently selected row
var row = $('#grid').jqGrid('getGridParam','selrow');
// A pop-up dialog will appear to confirm the selected action
if (row != null) {
$('#grid').jqGrid('delGridRow', row, {
url: 'delete.htm',
recreateForm: true,
beforeShowForm: function (form) {
//Change title
$(".delmsg").replaceWith('<span style="white-space: pre;">' +
'Delete selected record?' + '</span>');
//hide arrows
$('#pData').hide();
$('#nData').hide();
},
reloadAfterSubmit: true,
closeAfterDelete: true,
serializeDelData: function (postdata) {
var rowdata = $('#grid').getRowData(postdata.id);
// append postdata with any information
return {
id: postdata.id,
oper: postdata.oper,
username: rowdata.username
};
},
afterSubmit: function (response, postdata) {
var result = eval('(' + response.responseText + ')');
var errors = "";
if (result.success == false) {
for (var i = 0; i < result.message.length; i++) {
errors += result.message[i] + "<br/>";
}
} else {
$('#msgbox').text('Entry has been deleted successfully');
$('#msgbox').dialog({
title: 'Success',
modal: true,
buttons: {
"Ok": function () {
$(this).dialog("close");
}
}
});
}
// only used for adding new records
var newId = null;
return [result.success, errors, newId];
}
});
} else {
$('#msgbox').text('You must select a record first!');
$('#msgbox').dialog({
title: 'Error',
modal: true,
buttons: {
"Ok": function () {
$(this).dialog("close");
}
}
});
}
}
我收到以下错误:错误状态:“错误请求”。错误代码:400 删除所选记录?我在控制器或 jq 网格中遇到错误?请建议