다른 리소스로 나머지 웹 서비스를 설정했습니다. 그 중rest - json 응답에 알 수없는 필드가 있습니다.
하나는/API를 통해 액세스 할 수있는 고객/고객
입니다고객 클래스의 ID, 주소, 이름과 이메일 필드가 있지만 어떤 이유로 JSON 응답은 다음과 같습니다
{
"type": "customer",
"address": {
"city": "Kottes-Purk",
"country": "Pakistan",
"street": "Julius-Raab-Straße 008"
},
"email": "[email protected]",
"name": "Prof. Dr. David Mikitenko"
}
왜 json 응답에 "type"필드가 있는지 알지 못합니다. 누군가 거기에 왜 있는지 설명 할 수 있을까요?
고객 클래스는 다음과 같습니다 다음 CustomerResource 클래스에서
@XmlRootElement
@Entity
@Table(name = "customers")
public class Customer extends Model {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@Column(name = "name")
private String name;
@Column(name = "email")
private String email;
@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
@JoinColumn(name = "address_id")
private Address address;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "customer")
private List<Booking> bookings;
public Customer() {}
public Customer(String email, Address address, String name) {
this.email = email;
this.address = address;
this.name = name;
}
public int setId() {
return id;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
@XmlTransient
public List<Booking> getBookings() {
return bookings;
}
public void setBookings(List<Booking> bookings) {
this.bookings = bookings;
}
public static List<Customer> all() {
return (List<Customer>) Database.all(Customer.class);
}
public static Customer find(int id) {
return (Customer) Database.find(Customer.class, id);
}
public static boolean exists(int id) {
return Database.exists(Customer.class, id);
}
public static List<Customer> where(String column, String value) {
return (List<Customer>) Database.where(Customer.class, column, value);
}
}
:
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Customer> getCustomers(){
return agencyManager.getCustomers();
}
를 내가 여기 실종 무엇? ': "고객", "유형"'에 추가 할 수 있기 때문에 사용자의 ID 세터의
public abstract class Model implements Serializable {
public void save() {
EntityManager entityManager = HibernateUtil.getEntityManagerFactory().createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(this);
entityManager.getTransaction().commit();
entityManager.close();
}
public void delete() {
EntityManager entityManager = HibernateUtil.getEntityManagerFactory().createEntityManager();
entityManager.getTransaction().begin();
entityManager.remove(entityManager.contains(this) ? this : entityManager.merge(this));
entityManager.getTransaction().commit();
entityManager.close();
}
}
'Model' 클래스에 유형이 있습니까? – iNan
@ iNan no. 모델 클래스에는 두 개의 public 메소드 만 있습니다. – Lamevire
'Customer'의 한 인스턴스를 기록하고 ID가 설정되었는지 여부를 확인할 수 있습니다. – iNan