Контроллер:Spring @RequestBody Тип содержимого не поддерживается
@RestController
public class ExampleCtrl {
@RequestMapping(name="/example", method=RequestMethod.POST)
public String example(@RequestBody String request) {
System.out.println("example: " + request);
return "OK";
}
}
И запрос (Linux консоль):
curl -i -X POST 'https://localhost/example' -k -d 'name=value'
А весной консоли вывода:
example: name=value
Но когда я использую @ RequestBody Запрос запроса вместо @RequestBody String Не работает:
@RestController
public class ExampleCtrl {
@RequestMapping(name="/example", method=RequestMethod.POST)
public String example(@RequestBody Request request) {
System.out.println("example: " + request);
return "OK";
}
}
@JsonIgnoreProperties(ignoreUnknown=true)
class Request {
private String name;
public Request() {}
public String getName() {
return name;
}
}
У меня есть исключение:
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
EDIT Решенный. Она работает, когда я использую
curl -i -X POST 'https://localhost/example' -k -d '{"name": "value"}' --header "Content-Type:application/json"