gpt4 book ai didi

javascript - 向现有 Rest 服务添加新参数

转载 作者:行者123 更新时间:2023-12-01 22:09:28 25 4
gpt4 key购买 nike

我在 Java 后端有一个现有的 Rest 服务,如下所示:

@RequestMapping(value = "/service/{a}/{b}/{c}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public Response service(@PathVariable Long a, @PathVariable String b, @PathVariable String c, @RequestBody List<String> d)

它在 GUI 中被 JS 调用,如下所示:

$http.post(
'/service/'
+ a + '/'
+ b + '/'
+ c,
d)

我只需要添加一个新参数“e”,并尝试将其添加为新的路径变量:

@RequestMapping(value = "/service/{a}/{b}/{c}/{e}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public Response service(@PathVariable Long a, @PathVariable String b, @PathVariable String c, @PathVariable String e, @RequestBody List<String> d)
$http.post(
'/service/'
+ a + '/'
+ b + '/'
+ c + '/'
+ e,
d)

但是JS现在无法调用服务。据我所知,这应该可以正常工作。我错过了什么吗?

在 Tomcat 8.5 上运行代码,通过 Google Chrome 版本 78.0.3904.87 访问 GUI。控制台中出现以下错误:

Error: [$rootScope:inprog] http://errors.angularjs.org/1.4.3/$rootScope/inprog?p0=%24apply
at angular.min.js:6
at r (angular.min.js:127)
at n.$apply (angular.min.js:135)
at HTMLDivElement.<anonymous> (angular.min.js:252)
at HTMLDivElement.dispatch (jquery.min.js:3)
at HTMLDivElement.r.handle (jquery.min.js:3)
at FiberInvenInfoController.fiberInfo.disconnectAllCircuits (FiberInvenInfoController.js:714)
at n.$scope.ok (ModalServiceFiberInfo.js:428)
at fn (eval at compile (angular.min.js:212), <anonymous>:2:197)
at f (angular.min.js:252)
(anonymous) @ angular.min.js:108
(anonymous) @ angular.min.js:80
$apply @ angular.min.js:135
(anonymous) @ angular.min.js:252
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
FiberInvenInfoController.fiberInfo.disconnectAllCircuits @ FiberInvenInfoController.js:714
$scope.ok @ ModalServiceFiberInfo.js:428
fn @ VM866:2
f @ angular.min.js:252
$eval @ angular.min.js:134
$apply @ angular.min.js:135
(anonymous) @ angular.min.js:252
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
angular.min.js:92

POST http://.../rest/fiber/disconnectCircuits/7977/11-04-2019/user/PD 404
(anonymous) @ angular.min.js:92
n @ angular.min.js:88
f @ angular.min.js:86
(anonymous) @ angular.min.js:120
$eval @ angular.min.js:134
$digest @ angular.min.js:132
$apply @ angular.min.js:135
(anonymous) @ angular.min.js:252
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3

最佳答案

可能是 Spring 中的错误,请看这里: https://jira.spring.io/browse/SPR-6741在 v4.1 中已修复。

关于javascript - 向现有 Rest 服务添加新参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58668559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com