@PathVariable 的使用

场景:点击页面上一条数据的a标签,更改数据的状态

 

实现:
 

/**
     * 确认或退回时执行
     */
    @RequestMapping(value = "/statusChange/{id}/{status}")
    @ResponseBody
    public ApiResponses<Void> statusChange(@PathVariable("id") String id,
                                           @PathVariable("status") String status,
                               HttpServletResponse response){
            appOverShipmentService.statusChange(id, status);
            return success();
    }
                    <td>
                        <a class="fontBlue" href="#" th:value="${item.overShipmentId}" onclick="comfirmStatus(this)">确认</a>
                        | <a class="fontBlue" href="#" th:value="${item.overShipmentId}" onclick="backStatus(this)">退回</a>
                    </td>
/**状态确认操作*/
function comfirmStatus(obj) {
    var id = $(obj).attr("value");
    $.ajax({
        url: "/moreorless/confirm/statusChange/"+id+"/S",
        data: {id: id},
        type: 'post',
        success: function (data) {
            if (data.status === 200) {
                art.dialog({
                    title: '提示', content: '成功确认!', ok: function () {
                        window.location.reload();
                    }
                });
            } else {
                art.dialog({icon: 'error', content: "确认失败"});
            }
        }
    });
}

确认和退回的js基本一样

遇到的困难:

本来不想在写js,希望通过点击a标签直接更改。虽然可以达到更改状态,但是点击后主页直接刷新,form表单的查询的数据被清空,只好写js,不会将form表单的查询数据清空。

本来只写a标签是这样:

                     <td>
                        <a class="fontBlue"
                           th:href="'/moreorless/confirm/statusChange/'+${item.overShipmentId}+'/S'" target="_self">确认</a>
                        | <a class="fontBlue" th:href="'/moreorless/confirm/statusChange/'+${item.overShipmentId}+'/B'" target="_self">退回</a>
                    </td>

这样效果不理想,表单数据会被清空。

 

参考:https://zhidao.baidu.com/question/315770213.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值