2017-09-27 10 views
1

で見つけます:春休憩コントローラは、私は私の春RestControllerで次のメソッドを持っているID/IDS法

@RequestMapping(value = "/{decisionIds}", method = RequestMethod.GET) 
    public List<DecisionResponse> findByIds(@PathVariable @NotNull @DecimalMin("0") Set<Long> decisionIds) { 
.... 
} 

次の2つの方法は一緒に機能しません。

この機能を実装する正しい方法は何ですか?私は{decisionIds}を待っているメソッドを1つだけ残すべきですか?オブジェクトが1つだけ必要な場合でもコレクションを返します(Decision)?これを実装する別の適切な方法がありますか?

答えて

1

あなたは両方を単一のlong値を送信するだけでなく、長い値の配列のための単一のエンドポイントを作成することができます

http://localhost:8080/11,12,113,14

2

あなたは同じエンドポイントで2つの異なる方法を使用することはできません。言い換えれば

、あなたは同時に、これらの2つのメソッドを持つことはできません。

@RequestMapping(value = "/{decisionId}", method = RequestMethod.GET) 
    public DecisionResponse findById(@PathVariable @NotNull @DecimalMin("0") Long decisionId) { 
.... 
} 
@RequestMapping(value = "/{decisionIds}", method = RequestMethod.GET) 
    public List<DecisionResponse> findByIds(@PathVariable @NotNull @DecimalMin("0") Set<Long> decisionIds) { 
.... 
} 

@RequestMapping(value = "/{decisionIds}", method = RequestMethod.GET) 

そして

@RequestMapping(value = "/{decisionId}", method = RequestMethod.GET) 

ので、同じエンドポイントです。

したがって、http://<host>/19にHTTPリクエストGETがある場合は、使用する方法を判断できません。

ソリューションは、私は、これはあなたを助けることを願っています競合

@RequestMapping(value = "/decision/{Id}", method = RequestMethod.GET) 

そして

@RequestMapping(value = "/decisions/{Id}", method = RequestMethod.GET) 

を避けるために、より明確に自分のエンドポイントの名前を変更します。

@RequestMapping(value = "/{decisionIds}", method = RequestMethod.GET) 
    public List<DecisionResponse> findByIds(@PathVariable @NotNull @DecimalMin("0") Set<Long> decisionIds) { 
      System.out.println(decisionIds); 
} 

をそして、このようにパス変数を送信することによって、このエンドポイントを呼び出す:

関連する問題