Java – different methods for mapping spring requests to specific path variable values
•
Java
@Controller
@Controller @RequestMapping("/authors") public class AuthorController { @RequestMapping(value = "/{id}",method = RequestMethod.GET) public Author getAuthor( final HttpServletRequest request,final HttpServletResponse response,@PathVariable final String id) { // Returns a single Author by id return null; } @RequestMapping(value = "/{id}/author-properties",method = RequestMethod.GET) public AuthorProperties getAuthorProperties( final HttpServletRequest request,@PathVariable final String id) { // Returns a single Author's List of properties return null; } @RequestMapping // How to map /authors/*/author-properties to this method ???? public List<AuthorProperties> listAuthorProperties( final HttpServletRequest request,final HttpServletResponse response) { // Returns a single Author's List of properties return null; } } class Author { String propertiesUri; // other fields } class AuthorProperties { String authorUri; // other fields }@H_403_8@基本上我需要:
> / authors – 列出所有作者
> / authors / 123 – 通过id 123获取作者
> / authors / 123 / author-properties – 为123作者提取AuthorProperties对象
> / authors / * / author-properties – 获取所有作者的AuthorProperties列表当我尝试
@RequestMapping(value = "/*/author-properties",method = RequestMethod.GET)@H_403_8@它仍将map / authors / * / author-properties映射到getAuthorProperties方法,路径变量值为“*”.
Solution
See if this works
@RequestMapping(value = "/{id:.*}/author-properties",method = RequestMethod.GET)@H_403_8@
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码