从用户那里获取密码值,我想在网址路径中使用此密码,我使用百里香叶作为模板引擎

问题描述 投票:0回答:2

我在从用户那里获取密码值时遇到问题,我想在URL路径中使用此密码,我将百里香叶用作模板引擎。

这是我的控制器

    @RequestMapping(value = "/findEvent/{passcode}", method = RequestMethod.POST)
    public String findEvent(@PathVariable("passcode") String passcode,
                            final RedirectAttributes redirectAttributes, Model model) {

        Event event=eventService.findByPassCode(passcode);
        List<Question> questions=questionService.findQuestionsByPasscode(passcode);

        model.addAttribute("questions",questions);

        return "questions";
    }

这是我的html页面

addEvent.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <title>Hello World!</title>
</head>
<body>
<form method="post" th:action="@{/eventSave}" th:object="${eventRegister}">
    Name:<br>
    <input type="text" th:field="*{eventName}"><br>
    Passcode:<br>
    <input type="text" th:field="*{eventPasscode}"><br>

    <input type="submit" value="Submit">
</form>
</body>
</html>

passcode.html

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="post" th:action="@{/findEvent/{passcode}}">

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

    <input type="submit" value="Submit">
</form>
</body>
</html>

questions.html

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div class="col-12">
    <table class="table table-bordered">
        <tr>
            <th>Question </th>
            <th>Votes </th>

        </tr>
        <tr th:each="questions : ${questions}" th:object="${question}">
            <td th:text="*{text} "></td>
            <td th:text="*{voteValue} "></td>

            <a th:href="@{/voteQuestion/{id} (id=${question.questionId})}">Vote the question</a>
        </tr>
    </table>
</div>

and this is my result http://localhost:8080/findEvent/%7Bpasscode%7D

java spring thymeleaf template-engine
2个回答
0
投票

如果您希望表单操作URL包含表单本身的值,那么您需要一个onSubmit处理程序来更新表单字段中的URL。

表单值仅自动包含在POST请求的body中,或作为[[0]请求的query parameters

与JavaScript代码有关的其他事情。


0
投票

您的关键字是GET。搜索一下 ;)query string in spring

© www.soinside.com 2019 - 2024. All rights reserved.