繁体   English   中英

Spring-boot 休息 api。 截断尾部斜杠

[英]Spring-boot rest api. Truncate trailing slash

我有一个spring-boot rest api。

在我的application.properties我有:

server.port=8100
server.contextPath=/api/users

有一个控制器:

@RestController
@RequestMapping("")
public class UserService {
    @RequestMapping(value = "", method = POST, produces = "application/json; charset=UTF-8")
    public ResponseEntity<UserJson> create(@RequestBody UserJson userJson) {
    ...
    }
}

当我打电话时:

POST http://localhost:8100/api/users/注意尾部斜杠(带有用户的 json) - create方法执行正常。

但是当我打电话时:

POST http://localhost:8100/api/users不带斜杠(使用用户的 json) - 我收到405错误:

{ "timestamp": 1520839904193, "status": 405, "error": "Method Not Allowed", "exception": "org.springframework.web.HttpRequestMethodNotSupportedException", "message": "Request method 'GET' not supported", "path": "/api/users/" }

我需要没有斜杠的 URL,只是.../api/users ,为什么它被视为GET方法?

如果我改变server.contextPathserver.contextPath=/api@RequestMapping在我RestController到@RequestMapping("/users")一切工作正常。 在 URL 末尾使用和不使用尾随斜杠调用create()方法。

暂无
暂无

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

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