基本上我不明白如何使用Postman发送数据rest-api类? 当我使用Postman运行rest-api来保存记录时,它给出了我不支持应用程序json格式的错误..
我有以下课程来代表多对多关系
package com.ps.usercourse;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ps.course.Course;
import com.ps.user.User;
@Entity
public class UserCourse implements Serializable
{
private static final long serialVersionUID = 46419863112677606L;
@EmbeddedId
private UserCourseId id;
@ManyToOne
@MapsId("emailId")
@JsonBackReference
User user;
@ManyToOne
@MapsId("courseId")
@JsonBackReference
Course course;
Boolean isActive = true;
public UserCourse() {
}
public UserCourse(User user, Course course, Boolean isActive) {
this.user = user;
this.course = course;
this.isActive = isActive;
}
public UserCourse(UserCourseId id, User user, Course course, Boolean isActive) {
this.id = id;
this.user = user;
this.course = course;
this.isActive = isActive;
}
public UserCourseId getId() {
return id;
}
public void setId(UserCourseId id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
public Boolean getIsActive() {
return isActive;
}
public void setIsActive(Boolean isActive) {
this.isActive = isActive;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass())
return false;
UserCourse that = (UserCourse) o;
return Objects.equals(user, that.user) &&
Objects.equals(course, that.course);
}
@Override
public int hashCode() {
return Objects.hash(user, course);
}
}
这是我试图通过Postman打电话的休息api
@RequestMapping(value="/UserCourse",method=RequestMethod.POST)
@ResponseBody
public UserCourse addUser(@RequestBody UserCourse userCourse, HttpServletRequest req, HttpServletResponse res)
{
return userCourseService.save(userCourse);
}