SpringBootにて、「model」クラスではなく、「ModelAndView」をコントローラに使用している場合のバリデーションチェックの参考記事、もしくは方法などがあれば教えてください。
こちらの記事など基本的に、「Model」を使用し、formからの入力を受け取っている記事が多く、ModelAndViewの記事が見当たらない状況です。
実際のコントローラークラスのコードは以下になります。(バリデーションチェックは未実装です)
package com.example.demo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; // import org.springframework.ui.Model; // import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.servlet.ModelAndView; @Controller public class LoginController{ @RequestMapping(value="/login",method=RequestMethod.GET) public ModelAndView input(ModelAndView mav){ mav.setViewName("login"); return mav; } @RequestMapping(value="/top",method=RequestMethod.POST) public ModelAndView send(@RequestParam(value = "email",required = false)String email,@RequestParam(value = "pssword",required = false)String password,ModelAndView mav){ mav.addObject("email","emailは、" + email + "です。"); mav.addObject("password","passwordは、" + password + "です。"); mav.setViewName("top"); return mav; } }
以下は、form画面のテンプレートファイルになります。
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>ログイン画面</title> <link th:href="@{/css/login.css}" rel="stylesheet" type="text/css"> </head> <body> <div class="contain"> <div class="login_title"> <p>LOG IN</p> </div> <form class="login_form" method="post" action="/top"> <p><input class="mail_field" type="email" name="email" placeholder="Email"></p> <p><input class="password_field" type="password" name="password" placeholder="Password"></p> <p><input class="login_btn" type="submit" value="Log in"></p> </form> </div> </body> </html>

回答1件
あなたの回答
tips
プレビュー