3
は3つのRESTリソースを考えてみましょう:一覧
/persons/id/{id}
/persons/code/{code}
/persons/email/{email}
私はこれらの要求を処理するためにSpring MVC
コントローラで一つの方法を作りたい:
@RequestMapping("/persons/{searchField}/{searchValue}")
public Person search(@PathVariable field, @PathVariable value) {
...
}
質問です:の値リスト変数を注釈レベルに制限するエレガントな方法は、方法search
でチェックするだけですか?
switch (field) {
case "id": ...
case "code": ...
...
default: // not found exception??
}
しないでください。適切なパスを持つ3つのメソッドをそれぞれ定義します。 –
エレガントな方法は、Sotiriosが上記の – holtc
で述べたように、searchFieldの許容値ごとにメソッドを定義することです。@RequestMapping( "/ persons")とPathVariableではなくRequestParamを使用しますか? – Aroniaina