Spring提交表单获取复选框值不起作用

时间:2016-08-01 12:51:21

标签: java spring checkbox submit

我无法获得“记住我”复选框值(获取400必需布尔参数'记住'不存在)

尝试使用@RequestParam。 (输入电子邮件/密码)。 如何获取复选框值而不是400错误?

控制器


    @RequestMapping(value = "/login", method = RequestMethod.POST)
    private String doLogin(@RequestParam(value = "inputEmail") String inputEmail,
                           @RequestParam(value = "inputPassword") String inputPassword,
                           @RequestParam(value = "remember") boolean remember,
                           HttpSession session) {



HTML表单

    <form class="form-login" method="post" action="/login">
                <h2 class="form-login-heading">Please log in</h2>
                <label for="inputEmail" class="sr-only">Email address</label>
                <input type="email" id="inputEmail" name="inputEmail" class="form-control" placeholder="Email address" required
                       autofocus>
                <label for="inputPassword" class="sr-only">Password</label>
                <input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="remember" value="remember-me"> Remember me
                    </label>
                </div>
                <button class="btn btn-lg btn-primary btn-block btn-login" type="submit">Log in</button>
            </form>

1 个答案:

答案 0 :(得分:0)

请删除值=&#34;记住我&#34;从你的复选框。

当您勾选复选框时,弹簧将映射字符串值&#34;记住我&#34;如我所知,布尔是不可能的。