@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,
final HttpServletResponse response,
@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
}
基本上我需要:彈簧請求映射到一個不同的方法,用於一個特定的路徑變量值
- /作者 - 列出所有作者
- /作者/ 123 - 通過ID 123 提取作者
- /authors/123/author-properties - 爲123作者獲取AuthorProperties對象
- /authors/*/author-properties - fetching所有作者的AuthorProperties列表
當我試圖
@RequestMapping(value = "/*/author-properties", method = RequestMethod.GET)
它仍與路徑變量值映射到/authors/*/author-properties
方法getAuthorProperties爲 「*」。
當我在/ {id}/author-properties的方法之前保留/ */author-properties的方法時,它開始工作。那麼這是一個合適的解決方案?我們是否總是可以按照方法聲明的順序來處理映射的順序? – Litty