我使用Spring Boot。 我沒有web.xml和jsp文件如何將數據從HTML傳輸到控制器Spring
我有一個處理數據並將其寫入數據庫的控制器。
@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>
如何從頁數據傳輸到控制器?
感謝您的幫助
您指定'消耗= MediaType.APPLICATION_JSON_VALUE',你必須發送Json數據到你的控制器。 – Zorglube