これはよくある問題のように感じますが、私が調査したことはまだ何も機能していません...
私のweb.xmlには、すべてのREST呼び出しのマッピングがあります-
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
これは、URLが-の場合にうまく機能します
GET /rest/people
しかし、そうである場合は失敗します
GET /rest/people/1
と400 Bad Request
言うエラーが表示されますThe request sent by the client was syntactically incorrect ()
。ルーティングされるためにSpringサーブレットに到達したかどうかはわかりません...
適切に処理できるように、で始まるものをワイルドカード化するにはどうすればよいですか?/rest
言い換えれば、私は次のすべてが有効であることを望みます-
GET /rest/people
GET /rest/people/1
GET /rest/people/1/phones
GET /rest/people/1/phones/23
編集-要求に応じてコントローラーコード
@Controller
@RequestMapping("/people")
public class PeopleController {
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody String getPeople() {
return GsonFactory.getInstance().toJson(LookupDao.getInstance().getPeople());
}
@RequestMapping(value="{id}", method=RequestMethod.GET)
public @ResponseBody String getPerson(@PathVariable String id) {
return GsonFactory.getInstance().toJson(LookupDao.getInstance().getPerson(id));
}
}
答え
@matsev私がそこにいたかどうかは問題ではなかったようです/
。
パブリックビューの変数名を置き換えている間に、それが機能するようにいくつかの変更を加えました。
オリジナル
@RequestMapping(value="{id}", method=RequestMethod.GET)
public @ResponseBody String getPerson(@PathVariable String userId) {
return GsonFactory.getInstance().toJson(LookupDao.getInstance().getPerson(userId));
}
私が投稿したもの
@RequestMapping(value="{id}", method=RequestMethod.GET)
public @ResponseBody String getPerson(@PathVariable String id) {
return GsonFactory.getInstance().toJson(LookupDao.getInstance().getPerson(id));
}
変数名の不一致が発生しました...これをすべての人への警告としてここに残します...変数名を一致させてください!