![](/img/trans.png)
[英]Could not find acceptable representation - 406 Not Acceptable error
[英]“Could not find acceptable representation” 406
我正在嘗試執行POST
操作:
我的控制器是:
@RestController
@RequestMapping({"/contacts"})
public class ContactController {
...
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE,
produces = {MediaType.APPLICATION_ATOM_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
public Contact create(@RequestBody Contact contact){
return repository.save(contact);
}
聯系人模型是這樣的:
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class Contact {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String email;
private String phone;
public Contact(Long id, String name, String email, String phone) {
super();
this.id = id;
this.name = name;
this.email = email;
this.phone = phone;
}
public Contact(String name, String email, String phone) {
super();
this.name = name;
this.email = email;
this.phone = phone;
}
public Contact() {
super();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
我使用POSTMAN進行POST操作,因此:
url: http://localhost:8080/contacts (POST)body: JSON(application/json)--> {
"name": "Desperados",
"email": "fra@jot.it",
"phone": "88870999"
}
header: Content-type: application-json
我得到這個例外:
{
"timestamp": "2019-06-27T10:07:07.803+0000",
"status": 406,
"error": "Not Acceptable",
"message": "Could not find acceptable representation",
"path": "/contacts"
}
有人可以幫助我嗎?
1)默認情況下,rest控制器使用並生成JSON,您可能不需要提及它。 2)確保在PostMan中指定內容類型
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.