Answer the question
In order to leave comments, you need to log in
Why isn't MediaType supported in the controller?
Good afternoon.
There is such an endpoint
@PostMapping(value = "/products/add", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String addProduct(@RequestBody ProductDTO productDTO) {
service.addProduct(productDTO);
return "redirect:/products";
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8"/>
<title>Add product</title>
</head>
<body>
<div>
<form action="#" th:action="@{/products/add}" th:object="${productDTO}" method="post">
<input type="hidden" name="id">
<input type="text" name="productName" placeholder="Press name" />
<input type="text" name="productDescription" placeholder="Press description">
<input type="number" name="productPrice" placeholder="Press price">
<input type="number" name="stockBalance" placeholder="Press stockbalance">
<button type="submit">Add product</button>
</form>
</div>
</body>
</html>
Resolved exception caused by Handler execution: org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question