错误org.springframework.web.HttpMediaTypeNotSupportedException

时间:2016-03-13 22:23:19

标签: java spring-mvc spring-boot

我有一个问题,我的控制器上的休息和方法帖子我有这个2类,第一个是我的类用户的用户我有getters和setter的类以及默认的构造函数因为最后我想使用Hibernate 。:

@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主要发布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);
    }

我得到这个错误我使用postman进行查询和我的查询参数我发送这个Json查询:

{"id":"3","nom":"Gille","prenom":"Laurent","admin":"1","actif":"0","logins":"gilaur","email":""toto@hotmail.com,"naissance":"1990/09/09","pwd":"gal","compte":"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/"}

谢谢

1 个答案:

答案 0 :(得分:4)

enter image description here

您是Postman中的更改标题内容类型application/json,因为您尝试设置text/plain