给用户界面加一个删除功能
好难,我找了半天无处下手
要先写@controle
//以上都不对 正经的来了
-------------------------分割线-------------------------
我们用到两个文件
在DelAction中写删除操作,test_list.jsp是响应界面
先在DelAction中写方法
@RestController
//路径名
@RequestMapping("/test/del")
public class DelAction extends BaseController {
@Autowired
private BaseService<MallCategory> mallCategoryBaseService;
@Autowired
private MallCategoryService mallCategoryService;
//删除分类路径名
@RequestMapping("/delm")
public void delCategory() throws Exception {
Json json = new Json();
//此项目运用,获取用户名为admin
Puser user = (Puser) session.getAttribute(Constant.USER_SESSION);
String delId=req.getParameter("id");
//传model
MallCategory mallCategory =mallCategoryBaseService.get(MallCategory.class,delId);
if (StringUtils.isObjectNotEmpty(mallCategory)) {
//删除,有两种方式.
mallCategoryBaseService.delete(mallCategory);
//是否成功
json.setSuccess(true);
json.setMsg("删除成功");
} else {
json.setMsg("不存在");
}
super.writeToJson(json);
}
}
然后在test_list.jsp中
unction delAreaCode(id, name) {
$.messager.confirm('提示', "确定要删除“" + name + "”吗", function (r) {
if (r) {
$.ajax({
type: "POST",
url: "${pageContext.request.contextPath}/test/del/delm.action",
//不全
url: "${pageContext.request.contextPath}/test/del/delm.action
和上面的路径名对应.
补充
今天发现还需要初始化表格
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script type="text/javascript">
$(function () {
<!--初始化-->
$('#message-table').datagrid({
url: "${pageContext.request.contextPath}/mall/mallCategoryAction/getCategoryList.action",
singleSelect: true,
pagination: true,
...
中间省略
...
<!--和前面初始化-->
<table id="message-table">
</table>