不明点
ECサイトを作っているのですが
新規会員登録をする際に@{/user/regist/input/customer}の画面に遷移することが出来ません。
パスを変えたりもしたのですがうまくいきません。
助言をお願いいたします。
HTML
1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org"> 3<head> 4<meta charset="UTF-8" /> 5</head> 6<body> 7<div th:fragment="layout-header" class="container"> 8 <h1 class="site_title">ショップ</h1> 9 <div th:if="${session.user != null and session.user.authority == 2}" class="user_info"> 10 <a th:href="@{/user/detail/customer/{id}(id=${session.user.id})}" th:text="${session.user.name}"></a>さん、ようこそ | <a th:href="@{/logout}">ログアウト</a> 11 </div> 12 <div th:if="${session.user != null and (session.user.authority == 0 or session.user.authority == 1)}" class="user_info"> 13 <a th:href="@{/user/detail/admin/{id}(id=${session.user.id})}" th:text="${session.user.name}"></a>さん、ようこそ | <a th:href="@{/logout}">ログアウト</a> 14 </div> 15 <div th:if="${session.user == null}" class="user_info"> 16 <a th:href="@{/login}">ログイン</a> | <a th:href="@{/user/regist/input/customer}">新規会員登録</a> 17 </div> 18</div> 19</body> 20</html>
Controller
1package jp.co.sss.shop.controller.user; 2import javax.servlet.http.HttpSession; 3import javax.validation.Valid; 4import org.springframework.beans.BeanUtils; 5import org.springframework.beans.factory.annotation.Autowired; 6import org.springframework.stereotype.Controller; 7import org.springframework.ui.Model; 8import org.springframework.validation.BindingResult; 9import org.springframework.web.bind.annotation.ModelAttribute; 10import org.springframework.web.bind.annotation.RequestMapping; 11import org.springframework.web.bind.annotation.RequestMethod; 12import org.springframework.web.servlet.mvc.support.RedirectAttributes; 13import jp.co.sss.shop.entity.User; 14import jp.co.sss.shop.form.UserForm; 15import jp.co.sss.shop.repository.UserRepository; 16/** 17* 一般会員 新規登録機能(非会員)のコントローラクラス 18* 19* @author LenaKurata 20*/ 21@Controller 22public class UserRegistCustomerController { 23 /** 24 * 会員情報 25 */ 26 @Autowired 27 UserRepository userRepository; 28 @Autowired 29 HttpSession session; 30 31 /** 32 * 会員情報入力画面表示処理 33 * 34 * @return "user/regist/user_regist_input_customer" 会員情報 登録入力画面へ 35 */ 36 @RequestMapping(path = "/user/regist/input/customer",method=RequestMethod.GET) 37 public String registInput() { 38 return "user/regist/user_regist_input_customer"; 39 } 40 41 /** 42 * POSTメソッドを利用して会員情報入力画面に戻る処理 43 * 44 * @param form 会員情報 45 * @return "user/regist/user_regist_input_customer" 会員情報 登録入力画面へ 46 */ 47 @RequestMapping(path = "/user/regist/input/customer", method = RequestMethod.POST) 48 public String registInput(UserForm form) { 49 return "user/regist/user_regist_input_customer"; 50 } 51 /** 52 * 会員情報 登録確認処理 53 * 54 * @param form 会員情報フォーム 55 * @param result 入力チェック結果 56 * @return 入力値エラーあり:"redirect:/user/regist/input/customer" 会員情報登録画面へ 57 * 入力値エラーなし:"user/regist/user_regist_check_customer" 会員情報 登録確認画面へ 58 */ 59 @RequestMapping(path = "/user/regist/check/customer", method = RequestMethod.POST) 60 public String registCheck(@Valid @ModelAttribute UserForm form, BindingResult result, 61 RedirectAttributes redirectAttributes) { 62 // 入力値にエラーがあった場合、会員情報 入力画面表示処理に戻る 63 if (result.hasErrors()) { 64 redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.userForm", result); 65 redirectAttributes.addFlashAttribute("userForm", form); 66 return "redirect:/user/regist/input/customer"; 67 } 68 return "user/regist/user_regist_check_customer"; 69 } 70 /** 71 * 会員情報登録完了処理 72 * 73 * @param form 会員情報 74 * @return "redirect:/user/regist/complete/customer" 会員情報 登録完了画面へ 75 */ 76 @RequestMapping(path = "/user/regist/complete/customer", method = RequestMethod.POST) 77 public String registComplete(@ModelAttribute UserForm form) { 78 // 会員情報の生成 79 User user = new User(); 80 // 入力値を会員情報にコピー 81 BeanUtils.copyProperties(form, user); 82 // 会員情報を保存 83 userRepository.save(user); 84 return "redirect:/user/regist/complete/customer"; 85 } 86 /** 87 * 会員情報登録完了画面表示 88 * 89 * @param form 会員情報 90 * @return "user/regist/user_regist_complete_customer" 会員情報 登録完了画面へ 91 */ 92 @RequestMapping(path = "/user/regist/complete/customer", method = RequestMethod.GET) 93 public String registCompleteRedirect() { 94 return "user/regist/user_regist_complete_customer"; 95 } 96}
HTML
1<!DOCTYPE html> 2<html xmlns:th="http://www.thymeleaf.org" 3 th:replace="{common/layout_5block :: layout({::body/content()})}"> 4<head> 5<title>会員登録入力 | ショップ</title> 6<meta charset="UTF-8" /> 7</head> 8<body class="customer user_regist_input_customer"> 9 <h2 class="title">会員登録入力</h2> 10 <div class="user_info_form_area"> 11 <form method="post" th:action="@{/user/regist/check/customer}" th:object="${userForm}" class="user_info_form"> 12 <ul th:if="${#fields.hasErrors('*')}" th:class="input_list" > 13 <li th:each="err : ${#fields.errors('*')}" th:text="${err}" th:class="error_list" ></li> 14 </ul> 15 16 <ul class="input_list"> 17 <li> 18 <label> 19 <span class="input_title">メールアドレス</span> 20 <input type="text" name="email" th:value="${userForm.email}" th:field="*{email}" /> 21 </label> 22 </li> 23 <li> 24 <label> 25 <span class="input_title">パスワード</span> 26 <input type="password" name="password" th:value="${userForm.password}" /> 27 </label> 28 </li> 29 <li> 30 <label> 31 <span class="input_title">氏名</span> 32 <input type="text" name="name" th:value="${userForm.name}" /> 33 </label> 34 </li> 35 <li> 36 <label> 37 <span class="input_title">郵便番号</span> 38 <input type="text" name="postalCode" th:value="${userForm.postalCode}" /> 39 </label> 40 </li> 41 <li> 42 <label> 43 <span class="input_title">住所</span> 44 <textarea name="address" rows="6" th:text="${userForm.address}"></textarea> 45 </label> 46 </li> 47 <li> 48 <label> 49 <span class="input_title">電話番号</span> 50 <input type="text" name="phoneNumber" th:value="${userForm.phoneNumber}" /> 51 </label> 52 </li> 53 </ul> 54 <input type="submit" value="確認" class="send_button" /> 55 </form> 56 <form th:action="@{/user/list}"> 57 <input type="submit" value="戻る" class="back_button"/> 58 </form> 59 </div> 60</body> 61</html>
エラーメッセージ
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu Nov 14 15:06:49 JST 2019
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/user/regist/user_regist_input_customer.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/user/regist/user_regist_input_customer.html]")
at
回答2件
あなたの回答
tips
プレビュー