Thymeleaf请求参数空值问题

时间:2019-10-27 17:31:44

标签: java spring thymeleaf

我有一个问题,我的网络应用程序具有密码表单,用户将提供密码字符串,应用程序将使用户进入特殊事件的问题页面。即使通过此密码,我的控制器也可以找到它。我尝试过这种方式,但是我的密码字段始终为空。

<form method="get" th:action="@{/findEvent(passcode=${passcode})}">

    Passcode:<br>
    <input type="text"  th:name="${passcode}"><br>



    <div>
        <button type="submit">Find</button>
    </div>
</form>

    @GetMapping(value = "/findEvent")
    public String resetPassword(@RequestParam(value="passcode",required=false) String passcode) {
        if(passcode==null)
            return "passcode";
        Event event=eventService.findByPassCode(passcode);
        List<Question> questions=questionService.findQuestionsByPasscode(passcode);
        return "questions";
    }

    @RequestMapping(value = "/findEvent", method = RequestMethod.POST)
    public String findEvent(@RequestParam("passcode") String passcode) {
        Event event=eventService.findByPassCode(passcode);
        List<Question> questions=questionService.findQuestionsByPasscode(passcode);
        return "questions";
    }


我的问题

Request parameter with thymeleaf 我怎样才能做到这一点?你能帮我吗

1 个答案:

答案 0 :(得分:0)

改为使用name="passcode"

<input type="text"  name="passcode" value="1234" />

由于它与对象名称相同,因此只需使用

@RequestParam String passcode