gpt4 book ai didi

java - 错误 org.springframework.web.HttpMediaTypeNotSupportedException

转载 作者:行者123 更新时间:2023-12-01 18:06:35 26 4
gpt4 key购买 nike

我的 Controller 上的休息和方法发布有问题,我有这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.
*/
}

和我的类 Controller (用户 Controller ):用于使 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);
}

我得到了这个错误,我正在使用 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/"}

谢谢

最佳答案

enter image description here

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

关于java - 错误 org.springframework.web.HttpMediaTypeNotSupportedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35976627/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com