2017-08-09 19 views
0

/personsパスに複数のサーブレットを作成したいとします。クエリパラメータを持たないパスは、htmlページ(Thymeleafのテンプレートを使用)を提供するだけです。同じパスを持つ複数の@Getマッピングサーブレット?

パラメータを持つ人は、httpモデルにデータを代入する必要があります。

@Controller 
@RequestMapping("/persons") 
public class PricingCacheController { 

    //default just routing to the html template 
    @GetMapping(params = "") 
    public String personsHtml() { 
     System.out.println("initial page load"); 
     return "persons"; 
    } 

    @GetMapping 
    public String personsGet(Model model, @RequestParam MyBean bean) { 
     System.out.println("get request"); 
     model.addAttribute("dto", dao.findAll()); 
     return "persons"; 
    } 

localhost:8080/personsを実行

は、私が見つかりません 404を取得します。

+1

おそらく、[Spring Documentation](https://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann)を参照するほうがずっと簡単でしょう。 -requestmapping)を使用します。 '@PathVariable'と' @ RequestMethod'アノテーションを使ってHTTPメソッドを区別することができます – DevDio

答えて

0

これはできません。サーブレットマッピングはURLレベルで実行され、URLを解析するときにはクエリパラメータは無視されます。同じパス(クエリパラメータに関係なく)にマッピングする必要があるため、404パス変数?

関連する問題