我正在以以下格式{"name":"ABC","id":1}
,并尝试使用Employee
与Controller中的@Requestbody
类进行映射
但仍然出现错误,因为 HTTP状态415 –带有标题(内容类型:application / json)的不受支持的媒体类型
1)控制器:
@Controller
public class RegistrationController {
@Autowired
private EmployeeService employeeService;
@RequestMapping(path="/jsonreq", method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE)
public String json(@RequestBody Employee e)
{
System.out.println("JSON_2::");
return "Testing";
}
}
2)员工类别:
public class Employee {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}