Spring Hateoas 忽略查询参数
Spring Hateoas Ignoring Query Parameters
Spring Hateoas 没有为以下请求映射创建适当的 link:
@GetMapping("/member/{id}")
public MemberResource getMemberById(@RequestParam String id){
Member member = MemberService.getMemberById(id);
return new MemberResource(member);
}
public class MemberResource extends ResourceSupport{
public MemberResource(Member member){
add(linkTo(methodOn(MemberController.class).getMember(member.getId)).withSelfRel());
add(linkTo(methodOn(TeamsController.class).getTeams(memberId)).withRel("teams"));
}}
@GetMapping("/teams")
public List<TeamResource> getTeamsById(@RequestParam String id) {
List<Team> teams = teamService.getTeamsById(id);
return teams.stream().map(TeamResource::new).collect(Collectors.toList());
}
当调用 /member/12345 时期望 return:
{
member: {
//omitted for brevity
},
_links:[
{
href: .../members/12345
},
{
href: ../teams?memberId = 12345
}
]
}
而是 returns:
{
member: {
//omitted for brevity
},
_links:[
{
href: .../members/12345
},
{
href: ../teams/12345
}
]
}
这是为什么?即使我使用@RequestParam,它也完全忽略了过滤器。在此问题上,我们将不胜感激。
免责声明:从未使用过 Spring HATEOAS。
但乍一看,您似乎混淆了两种 URL-参数类型:
@PathVariable
对于像 .../teams/TEAM_ID
这样的路径变量
@RequestParam
查询参数如 .../teams?id=TEAM_ID
Spring Hateoas 没有为以下请求映射创建适当的 link:
@GetMapping("/member/{id}")
public MemberResource getMemberById(@RequestParam String id){
Member member = MemberService.getMemberById(id);
return new MemberResource(member);
}
public class MemberResource extends ResourceSupport{
public MemberResource(Member member){
add(linkTo(methodOn(MemberController.class).getMember(member.getId)).withSelfRel());
add(linkTo(methodOn(TeamsController.class).getTeams(memberId)).withRel("teams"));
}}
@GetMapping("/teams")
public List<TeamResource> getTeamsById(@RequestParam String id) {
List<Team> teams = teamService.getTeamsById(id);
return teams.stream().map(TeamResource::new).collect(Collectors.toList());
}
当调用 /member/12345 时期望 return:
{
member: {
//omitted for brevity
},
_links:[
{
href: .../members/12345
},
{
href: ../teams?memberId = 12345
}
]
}
而是 returns:
{
member: {
//omitted for brevity
},
_links:[
{
href: .../members/12345
},
{
href: ../teams/12345
}
]
}
这是为什么?即使我使用@RequestParam,它也完全忽略了过滤器。在此问题上,我们将不胜感激。
免责声明:从未使用过 Spring HATEOAS。
但乍一看,您似乎混淆了两种 URL-参数类型:
@PathVariable
对于像.../teams/TEAM_ID
这样的路径变量
@RequestParam
查询参数如.../teams?id=TEAM_ID