项目学习 第一天

给用户界面加一个删除功能

在这里插入图片描述
好难,我找了半天无处下手
要先写@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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值