【发布时间】:2017-09-16 19:37:07
【问题描述】:
我使用 Spring Boot。 我没有 web.xml 和 jsp 文件
我有一个控制器来处理数据并将其写入数据库。
@RequestMapping(value = "/registration", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Registration user", response = Account.class)
public AccountDto registration(@Valid @RequestBody RegistrationDto registration, HttpServletResponse response) {
Account account = new Account(registration.getEmail(), registration.getPassword());
return new AccountDto(account);
}
我在 Swagger 的帮助下检查了控制器。
我有一个 HTML 页面,用户可以在其中输入数据。
<body>
<h1 th:inline="text">Please register</h1>
<form th:action="@{/logout}" method="post">
<div>
<label>
E-mail:<input type="email" name="email"/>
Password:<input type="password" name="password"/>
</label>
</div>
<input type="submit" name="registration" value="Registration"/>
</form>
</body>
如何将数据从页面传输到控制器?
感谢您的帮助
【问题讨论】:
-
您指定了
consumes = MediaType.APPLICATION_JSON_VALUE,您必须将Json 数据发送到您的控制器。
标签: java html spring spring-mvc