【发布时间】:2017-12-02 00:23:32
【问题描述】:
我有一个带有以下 Post 代码的 RestController,并尝试在我的 AJAX 中使用它来在数据库表中添加数据。我有以下错误。
RestController 方法发布
@RequestMapping(method = RequestMethod.POST)
public void create(@RequestBody MessageChat chatmessage) {
messageService.save(chatmessage);
}
Ajax 调用
$( "#vut" ).on( "click", function(e){
e.preventDefault();
e.stopPropagation();
$.ajax({
url: '/messagechat',
method: 'POST',ContentType:'application/json',dataType: 'JSON',
data: {
message: 'a'
}
})
});
错误
{"timestamp":1498660502132,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported","path":"/messagechat"}
有人可以帮忙吗?
【问题讨论】:
标签: java hibernate rest spring-boot