繁体   English   中英

错误org.springframework.web.HttpMediaTypeNotSupportedException

[英]Error org.springframework.web.HttpMediaTypeNotSupportedException

我在控制器上的rest和方法发布有问题,我有这两个类,第一个是我的类用户中的用户,我有我的类与getter和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);
    }

我得到这个错误我正在使用邮差进行查询,并在我的查询参数中发送此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/"}

谢谢

在此处输入图片说明

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM