从网上下载了一个开源项目,然后发现 bug 太多,发现一个比较奇怪的问题,前端传值已经有值了,后端接收的时候只有一个 Float 的接收不到值。

前端代码

    $.ajax({
                    type: "PUT",
                    url: "/admin/node/${node.id}",
                    dataType: "json",
                    data: {
                        name: $("#name").val(),
                        server: $("#server").val(),
                        method: $("#method").val(),
                        custom_method: $("#custom_method").val(),
                        traffic_rate: $("#rate").val(),
                        info: $("#info").val(),
                        type: $("#type").val(),
                        status: $("#status").val(),
                        sort: $("#sort").val()
                    },
                    success: function (data) {
                        if (data.ret) {
                            $("#msg-error").hide(100);
                            $("#msg-success").show(100);
                            $("#msg-success-p").html(data.msg);
                            window.setTimeout("location.href='/admin/node'", 2000);
                        } else {
                            $("#msg-error").hide(10);
                            $("#msg-error").show(100);
                            $("#msg-error-p").html(data.msg);
                        }
                    },
                    error: function (jqXHR) {
                        $("#msg-error").hide(10);
                        $("#msg-error").show(100);
                        $("#msg-error-p").html("发生错误:" + jqXHR.status);
                    }
                });

后端代码

    @Route(value = "node/:id", method = HttpMethod.PUT)
        @JSON
        public Result update(@PathParam Integer id, @QueryParam String name, @QueryParam String server,
                             @QueryParam String method, @QueryParam int custom_method,
                             @QueryParam Float traffic_rate, @QueryParam String info,
                             @QueryParam int type, @QueryParam String status, @QueryParam int sort) {

            Node node = new Node();
            node.setId(id);
            node.setName(name);
            node.setServer(server);
            node.setMethod(method);
            node.setCustom_method(custom_method == 1);
            node.setTraffic_rate(traffic_rate);
            node.setInfo(info);
            node.setType(type);
            node.setStatus(status);
            node.setSort(sort);

            try {
                nodeService.update(node);
            } catch (Exception e) {
                LOGGER.error("修改节点失败", e);
                return Result.fail("修改失败");
            }
            return Result.ok("修改成功");
        }

@QueryParam Float traffic_rate 这个值一直都是 null

解决方法

目前还未找到,如果有人找到,欢迎留言!