2016-05-23 2 views
0

私は、Thymleafに以下の登録フォームを持っています。問題は私がログインページにリダイレクトするボタンを送信するときです。ここでフォームはメソッドを修正するためのパラメータを送信しません

は私のフォームです:

<form class="form-horizontal" th:object="${newCustomer}" th:method="post" th:action="@{/dashboard/NewUserRegisteration}"> 
       <div class="form-group"> 
        <label for="name" class="col-sm-2 control-label">Full Name</label> 
        <div class="col-sm-10"> 
         <input type="text" class="form-control" id="name" th:field="*{name}"></input> 
        </div> 
       </div> 

       <div class="form-group"> 
        <label for="name" class="col-sm-2 control-label">address</label> 
        <div class="col-sm-10"> 
         <input type="text" class="form-control" id="address" th:field="*{address}"></input> 
        </div> 
       </div> 

       <div class="form-group"> 
        <label for="name" class="col-sm-2 control-label">Phone</label> 
        <div class="col-sm-10"> 
         <input type="text" class="form-control" id="phone" th:field="*{phone}"></input> 
        </div> 
       </div> 

       <div class="form-group"> 
        <label for="name" class="col-sm-2 control-label">Password</label> 
        <div class="col-sm-10"> 
         <input type="password" class="form-control" id="password" th:field="*{password}"></input> 
        </div> 
       </div> 



       <div class="form-group"> 
        <label for="name" class="col-sm-2 control-label">Confirm Password</label> 
        <div class="col-sm-10"> 
         <input type="password" class="form-control" id="confirmPass" th:field="*{confirmPass}"></input> 
        </div> 
       </div>    


       <div class="form-group"> 
        <div class="col-sm-offset-2 col-sm-10"> 
         <button id="submit-button" type="submit" class="btn btn-default">Submit query</button> 
        </div> 
       </div> 
      </form> 

、ここでは、コントローラのメソッドです:あなたが見ることができるように

@RequestMapping(method=POST, path="dashboard/NewUserRegisteration") 
    public String RegisterNewCustomer(@RequestParam(name = "name") UserDTO userDTO){ 

     System.out.println("All Users are: "); 

     return "redirect:"+ "/dashboard/login"; 
    } 

、私はボタンを押すと"All Users are: "を印刷見ると期待が、それはdoesnの仕事はありません。 、ここで終わりではUserDTOクラスです:

@Data 
@NoArgsConstructor(force = true) 
public class UserDTO { 

    long id; 
    String name; 
    String address; 
    String phone; 
    String password; 
    String userName; 
    String confirmPass; 
} 
+0

ようにそれを破壊することを考えすることができる方法で

私は '@RequestParam(名前= "nameは")'ので、間違っていると仮定しますあなたのパラメータ名は 'newCustomer'であり、それはリクエストパラメータではなく、' ModelAttribute'です。 – sanluck

+0

もう1つ目は、 'System.out.println(" All Users are: ");'?おそらく、ロギングパラメータをチェックする必要がありますか? – sanluck

+0

@sanluckロギングパラメータを確認するにはどうすればよいですか? –

答えて

0

ナンバーワン、ログインページにリダイレクトしている、あなたはこれを指定することを検討しました?:

return "redirect:"+ "/dashboard/login"; 

それはあなたの意図ではなかった場合は、あなたのコードでは、コントローラメソッドの実行後に続くパスを指定しています。あなたはこの

`

@Autowired 
UserRepository userRepository; 
@RequestMapping(method = RequestMethod.POST, path="dashboard/NewUserRegisteration") 
public String RegisterNewCustomer(Model model){ 
    UserDTO user = new UserDTO(); 
    model.addAttribute("newCustomer",user); 
    userRepository.save(user); 
    return "redirect:/dashboard/login"; 
} 

`

関連する問題