简体   繁体   English

向现有 Rest 服务添加新参数

[英]Adding new parameter to existing Rest service

I have an existing Rest service in Java backend like such:我在 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)

It is being called by JS in a GUI as such:它是由 JS 在 GUI 中调用的,如下所示:

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

I simply need to add a new parameter "e", and have tried adding it as a new path variable:我只需要添加一个新参数“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)

But JS fails to call the service now.但是 JS 现在无法调用该服务。 From what I can tell this should work fine.据我所知,这应该可以正常工作。 Am I missing something?我错过了什么吗?

Running code on Tomcat 8.5, accessing GUI through Google Chrome version 78.0.3904.87.在 Tomcat 8.5 上运行代码,通过 Google Chrome 版本 78.0.3904.87 访问 GUI。 Following errors appear in console:控制台中出现以下错误:

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

Probably bug in Spring, look here: https://jira.spring.io/browse/SPR-6741 It is fixed in v4.1.可能是 Spring 中的错误,请看这里: https://jira.spring.io/browse/SPR-6741它已在 v4.1 中修复。

Spring Boot was not picking up the changes to new or existing Rest controllers. Spring 引导没有对新的或现有的 Rest 控制器进行更改。 Removing default package from the project, and doing a Project Build before each Publish to Tomcat has solved the issue.从项目中删除默认 package,并在每次发布到 Tomcat 之前进行项目构建已经解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM