Java 错误org.springframework.web.HttpMediaTypeNotSupportedException
我的控件上的rest和method post有一个问题我有两个类第一个是类中的用户用户我有一个带有getter和setter的类以及一个默认构造函数,因为最后我想使用HibernateJava 错误org.springframework.web.HttpMediaTypeNotSupportedException,java,spring-mvc,spring-boot,Java,Spring Mvc,Spring Boot,我的控件上的rest和method post有一个问题我有两个类第一个是类中的用户用户我有一个带有getter和setter的类以及一个默认构造函数,因为最后我想使用Hibernate @Entity @Table(name="Utilisateur") // mapping with hibernate (but not using in this situation) public class User { @Id private long id; @Column(
@Entity
@Table(name="Utilisateur") // mapping with hibernate (but not using in this situation)
public class User {
@Id
private long id;
@Column(name="nom")
private String nom;
@Column(name="prenom")
private String prenom;
@Column(name="admin")
private boolean admin;
@Column(name="actif")
private boolean actif;
@Column(name="logins")
private String logins;
@Column(name="email")
private String email;
@Column(name="naissance")
private String naissance;
@Column(name="pwd")
private String pwd;
@Column(name="compte")
private String compte;
public User(){
}
/*
with getter and setter.
*/
}
我的类控制器(用户控制器):用于使api主要是post api
@RestController
public class UserController {
@RequestMapping(
value="/api/greetings/post",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces=MediaType.APPLICATION_JSON_VALUE
)
@ResponseBody
public ResponseEntity<User> getByEmail(@RequestBody User user){
if(user==null){
return new ResponseEntity<User>(HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<User>(user, HttpStatus.OK);
}
我得到了这个错误:
{"timestamp":1457906727481,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'text/plain;charset=UTF-8' not supported","path":"/api/greetings/post/"}
谢谢
您正在邮递员中更改标题内容类型application/json
,因为您尝试设置text/plain
您在Postman中更改标题内容类型
application/json
,因为您尝试设置text/plain
谢谢,但当我使用您的方法时,我会收到相同的错误,但当我删除@RequestBody时,我会收到此错误。{“id”:0,“nom”:null,“prenom”:null,“admin”:false,“actif”:false,“logins”:null,“email”:null,“naissance”:null,“pwd”:null,“compte”:null}不要删除@RequestBody重试您的示例,但您的电子邮件不在“”括号中。您是否看到此“电子邮件”:“”toto@hotmail.comand使用此示例发送邮递员{“id”:“3”,“nom”:“Gille”,“prenom”:“Laurent”,“admin”:“true”,“actif”:“true”,“logins”:“gilaur”,“email”:toto@hotmail.com“,“诞生”:“1990/09/09”,“pwd”:“gal”,“compte”:“autre”}谢谢你,但在《邮差》中,我没有使用括号作为参数,我得到了相同的结果。谢谢你,但当我使用你的方法时,我得到了相同的错误,但当我删除@RequestBody时,我得到了这个错误。{“id”:0,“nom”:null,“prenom”:null,“admin”:false,“actif”:false,“logins”:null,“email”:null,“naissance”:null,“pwd”:null,“compte”:null}不要删除@RequestBody请重试您的示例,但您的电子邮件不在“”括号中。您是否看到此“电子邮件”:toto@hotmail.comand使用此示例发送邮递员{“id”:“3”,“nom”:“Gille”,“prenom”:“Laurent”,“admin”:“true”,“actif”:“true”,“logins”:“gilaur”,“email”:toto@hotmail.com,“诞生”:“1990/09/09”,“pwd”:“gal”,“COMPT”:“autre”}谢谢,但在《邮递员》中,我不使用括号来表示参数,我得到了相同的结果。
{"timestamp":1457906727481,"status":415,"error":"Unsupported Media Type","exception":"org.springframework.web.HttpMediaTypeNotSupportedException","message":"Content type 'text/plain;charset=UTF-8' not supported","path":"/api/greetings/post/"}