错误org.springframework.web.HttpMediaTypeNotSupportedException

扎夫拉尼

我在控制器上的rest和方法发布有问题,我有这个2类,第一个是我的类用户,我有我的类,带有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":""[email protected],"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/"}

谢谢

卡卡西哈卡特

在此处输入图片说明

您正在更改application/json邮递员中的标头内容类型,因为您尝试设置text/plain

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

org.springframework.web.client.HttpClientErrorException:401空

org.springframework.boot.web.support不存在

org.springframework.web.client.HttpClientErrorException:400错误的请求

错误[org.springframework.web.servlet.DispatcherServlet]

错误:org.springframework.web.HttpMediaTypeNotSupportedException:内容类型'text / plain; charset = UTF-8'不支持

java.lang.NoClassDefFoundError:org / springframework / web / util / UriTemplateHandler

找不到类org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer

org.springframework.web.multipart.MultipartFile和org.springframework.core.io.Resource之间的转换

HttpMediaTypeNotSupportedException

java.lang.NoClassDefFoundError:org / springframework / web / util / UriTemplateHandler

导入org.springframework.boot.autoconfigure.web.ErrorAttributes无法解析

java.lang.ClassNotFoundException:org.springframework.web.context.ContextLoaderListener

已解决由处理程序执行引起的异常:org.springframework.web.HttpMediaTypeNotSupportedException:内容类型'application / x-www-form

从Spring 3.0迁移到Spring 3.1时org.springframework.web.servlet.DispatcherServlet错误

org.springframework.web.client.HttpClientErrorException:RestTemplate中的400错误请求

找不到org.springframework.web.context.ContextLoaderListener类

ClassNotFoundException :: org.springframework.web.context.ContextLoaderListener

为什么org.springframework.boot不能导入,而org.springframework.web可以导入?

org.springframework.web.servlet.DispatcherServlet noHandlerFound

java.lang.NoClassDefFoundError:org / springframework / web / context / ContextCleanupListener问题

使用MockMVC的Spring集成测试抛出org.springframework.web.HttpMediaTypeNotSupportedException:内容类型'application / json'不支持

org.springframework.web.multipart.commons.CommonsMultipartFile无法转换为org.springframework.web.multipart.MultipartFile

找不到 org.springframework.web.servlet.mvc.SimpleFormController

Spring MVC 错误:org.springframework.web.servlet.DispatcherServlet noHandlerFound

在 Spring MVC 中出现错误 Missing artifact spring-web:org.springframework

找不到 org.springframework.web.WebApplicationInitializer

无法导入 org.springframework.web.multipart.MultipartFile;

警告:已解决 [org.springframework.web.HttpMediaTypeNotSupportedException:不支持内容类型“应用程序/json”]

严重:错误配置类 [org.springframework.web.context.ContextLoaderListener] NoClassDefFoundError: javax/servlet/ServletContextListener