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