我从角度5组件获得以下代码:
export class TripsComponent implements OnInit {
...
...
addTrip() {
let newTrip = new Trip(this.new_trip_name,
this.new_trip_description, this.company);
this.tripService.addTrip(newTrip).toPromise();
}
//The company object is initialize inside ngOnInit()
旅行服务如下:
addTrip(tripTemp: Trip): Observable<any> {
let tripObj = {
trip: tripTemp
};
console.log('Adding trip ' + JSON.stringify(tripObj));
return this.http.post(`${this.baseUrl}/Trips/Trip`, JSON.stringify(tripObj), httpOptions);
}
java rest api看起来像这样:
@POST
@Path("Trip")
@Produces("application/json")
@Consumes("application/json")
public Response addTrip(Trip trip) {
tripDao.addTrip(trip);
return Response.ok().entity("Trip added successfully").build();
}
旅行中的公司对象被注释为XmlTransit(不确定是否会引起问题):
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "company_id", nullable = false)
@XmlTransient
public Company getCompany() {
return this.company;
}
问题是公司对象作为NULL进入,这是必需的 字段以保存Trip对象。任何想法如何允许自动转换 为了这个内在的目的? 预先感谢。
答案 0 :(得分:0)
我必须删除@XmlTransient。