要将页面信息传递到控制器中,页面组件和控制器的注解、函数参数一定不能写错了,下面是个简单示例,有兴趣的可以参照:
html页面:
<div class="block-body"> <form action="userRegister" method="post"> <label>用户名</label> <input type="text" name="uname" class="span12"> <label>密码</label> <input type="password" name="pswd" class="span12"> <label>再次输入密码</label> <input type="password" name="repswd" class="span12"> <label>邮件地址</label> <input type="text" name="email" class="span12"> <input type="submit" value="Submit" class="btn btn-primary pull-right"/> <div class="clearfix"></div> </form> </div>
控制器:
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; @Controller public class UserCtrl { @PostMapping(value="/userRegister") public String register(String uname,String pswd,String repswd,String email) { return "login"; } }
对应好了,前后就通顺了。
END