首页 > 解决方案 > Spring @GetMapping 不适用于子资源

问题描述

我有一个控制器,看起来像这样。

@RestController("/some")
public class SomeController {

    @GetMapping(produces = {MediaType.APPLICATION_JSON_VALUE})
    public ResponseEntity<?> read(...) {
        ...
    }

    @GetMapping(path = "{id:\\d+}", produces = ...)
    public ResponseEntity<Some> readSingle(@PathVariable(name = "id") final int id) {
        ...
    }
}

控制器适用于父母。

curl http://.../some

但子资源返回与 相同/some

curl http://.../some/2 // returns the same with /some

我做错了什么?

标签: springspring-restcontroller

解决方案


我正在回答我自己的问题。

问题是类上的错误注释。

@RequestMapping(path = {...})
@RestController
public class SomeController {
}

推荐阅读