我在从用户处获取密码值时遇到问题,我想在 url 路径中使用此密码,我使用 thymeleaf 作为模板引擎。
这是我的 Controller
@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>
密码.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>
问题.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
最佳答案
如果您希望表单操作 URL 包含表单本身的值,则需要 onSubmit
处理程序以更新表单字段中的 URL。
表单值仅自动包含在 POST
的正文中请求,或作为 GET
的查询参数请求。
任何其他与 JavaScript 代码相关的事情。
关于java - 从用户处获取密码值,我想在 url 路径中使用此密码,我使用 thymeleaf 作为模板引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58578730/