SSM+Maven——修改加删除商品类型信息

1.前端页面:

<button class="btn btn-warning updateProType" onclick="modifyName()">修改</button>
 function modifyName(){
            $.ajax({
                type:'post',
                url:'${pageContext.request.contextPath}/backend/productType/modifyName',
                data:{'id': $('#proTypeNum').val(),'name':$('#proTypeName').val()},
                dataType:'json',
                success:function(result){
                    if(result.status==1){
                        layer.msg(result.message,{
                            time:2000,
                            skin:'successMsg'
                        },function(){
                            //关闭以后重新加载数据
                            location.href='${pageContext.request.contextPath}/backend/productType/findAll?pageNum='+${pageInfo.pageNum};
                        })
                    }else{
                        layer.msg(result.message,{
                            time:2000,
                            skin:'errorsMsg'
                        })
                    }
                }
            });
        }

2.Controller

	@RequestMapping("/modifyName")
    @ResponseBody
    public ResponseResult modifyName(int id,String name){
        try {
            productTypeService.modifyName(id,name);
            return ResponseResult.success("修改成功");
        } catch (ProductTypeExistException e) {
            //e.printStackTrace();
            return ResponseResult.fail(e.getMessage());
        }
    }

3.Service

@Override
    public void modifyName(int id, String name) throws ProductTypeExistException {
        ProductType productType = productTypeDao.selectByName(name);
        if(null!=productType){
            throw new ProductTypeExistException("商品类型名称已存在");
        }
        productTypeDao.updateName(id,name);
    }

4.Dao

public void updateName(@Param("id") int id, @Param("name") String name);

mapper.xml

<update id="updateName">
        update t_product_type
        set name=#{name}
        where id=#{id}
    </update>

删除功能:

1.前端

删除的按钮

<input type="button" class="btn btn-warning btn-sm doProTypeDelete" onclick="showDeleteModal(${productType.id})" value="删除">

点击后,利用js函数弹出删除面板

  //显示确认删除的提示 点击后将展开提示栏
        function showDeleteModal(id){
            $('#deleteProductTypeId').val(id);
            $('#deleteProductTypeModal').modal('show');
        }

删除的面板html代码:

<!-- 确认删除 start -->
<div class="modal fade" tabindex="-1" id="deleteProductTypeModal">
    <!-- 窗口声明 -->
    <div class="modal-dialog">
        <!-- 内容声明 -->
        <div class="modal-content">
            <!-- 头部、主体、脚注 -->
            <div class="modal-header">
                <button class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">提示消息</h4>
            </div>
            <div class="modal-body text-center">
                <h4>确认要删除该商品类型吗?</h4>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="deleteProductTypeId">
                <button class="btn btn-primary updateProType" onclick="deleteProductType()" data-dismiss="modal">删除</button>
                <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>

确定删除的js代码:

 //删除商品类型
        function deleteProductType(){
            $.get(
                '${pageContext.request.contextPath}/backend/productType/removeById',
                {'id':$('#deleteProductTypeId').val()},
                function(result){
                    if(result.status==1){
                        layer.msg('删除成功',{
                            time:2000,
                            skin:'successMsg'
                        },function(){
                            //重新加载数据
                            location.href='${pageContext.request.contextPath}/backend/productType/findAll?pageNum='+${pageInfo.pageNum};
                        })
                    }else{
                        layer.msg('删除失败',{
                            time:2000,
                            skin:'errorsMsg'
                        })
                    }
                }
            );
        }

2.Controller:

@RequestMapping("/removeById")
    @ResponseBody
    public ResponseResult removeById(int id){
        productTypeService.removeById(id);
        return ResponseResult.success();
    }

service、dao、mapper省略

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值