我的其他端点映射存在问题。它们涉及分层自然键。所以我想要缩短路径的路径,然后它会从更大的项目空间中获得结果。
问题是,最完全限定的路径是有效的,而leas限定路径是有效的,但不是中间的两条路径;他们返回404而没有进入控制器。所以我认为这是一个映射问题。任何帮助将不胜感激。
@RestController
@RequestMapping("/bookmark/v1")
public class BookmarkRestController
{
// this works
@GetMapping("/member/{memberId}/content/{contentSource}/{contentType}/{contentId}")
public ResponseEntity<Bookmark> read(
@PathVariable final String memberId,
@PathVariable final String contentSource,
@PathVariable final String contentType,
@PathVariable final String contentId)
{
...
}
// this returns 404 without ever getting into the controller
@GetMapping("/member/{memberId}content/{contentSource}/{contentType}")
public ResponseEntity<Iterable<Bookmark>> read(
@PathVariable final String memberId,
@PathVariable final String contentSource,
@PathVariable final String contentType)
{
...
}
// this returns 404 without ever getting into the controller
@GetMapping("/member/{memberId}content/{contentSource}")
public ResponseEntity<Iterable<Bookmark>> read(
@PathVariable final String memberId,
@PathVariable final String contentSource)
{
...
}
// this works
@GetMapping("/member/{memberId}")
public ResponseEntity<Iterable<Bookmark>> read(@PathVariable final String memberId)
{
...
}
}
@GetMapping("/member/{memberId}/content/{contentSource}/{contentType}/{contentId}")
public ResponseEntity<Bookmark> read(
@PathVariable final String memberId,
@PathVariable final String contentSource,
@PathVariable final String contentType,
@PathVariable final String contentId)
@GetMapping("/member/{memberId}content/{contentSource}/{contentType}")
public ResponseEntity<Iterable<Bookmark>> read(
@PathVariable final String memberId,
@PathVariable final String contentSource,
@PathVariable final String contentType)
@GetMapping("/member/{memberId}content/{contentSource}")
public ResponseEntity<Iterable<Bookmark>> read(
@PathVariable final String memberId,
@PathVariable final String contentSource)
@GetMapping("/member/{memberId}")
public ResponseEntity<Iterable<Bookmark>> read(@PathVariable final String memberId)
答案 0 :(得分:1)
您的网址映射对于这两种方法不正确,即您之间缺少/
,因此您需要将此/member/{memberId}content
更改为/member/{memberId}/content
/member/{memberId}content
url(out /
)仅在请求类似于/member/1content
时才有效。
换句话说,当控制器映射到/member/{memberId}content
url&amp;请求来自/member/1/content
9路径分隔符)您将收到404错误。