我有雙向關係。 這是我實體factura:收集null在AngularJS + Spring數據JPA @OneToMany @ManyToOne
@Entity
@Table(name = "T_FACTURA")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Factura implements Serializable {
...
@OneToMany(mappedBy = "factura")
@JsonIgnore
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Facturaservicio> facturaservicios = new HashSet<>();
...
@Override
public String toString() {
//all attributes except facturaservicios
}
}
這是我實體facturaservicio:
@Entity
@Table(name = "T_FACTURASERVICIO")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Facturaservicio implements Serializable {
...
@ManyToOne
private Factura factura;
...
@Override
public String toString() {
//all attributes except factura
}
}
這是我REST控制器
@RestController
@RequestMapping("/app")
public class FacturaResource {
private final Logger log = LoggerFactory.getLogger(FacturaResource.class);
@Inject
private FacturaRepository facturaRepository;
@RequestMapping(value = "/rest/facturas",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public List<Factura> getAll() {
log.debug("REST request to get all Facturas");
return facturaRepository.findAll();
}
這是我安固larJS控制器:
$http.get('app/rest/facturas').
success(function (data, status, headers, config) {
console.log(JSON.stringify(data));
});
爲什麼我的收藏是在AngularJS控制器空?我如何訪問收藏?
您在您的$ http.get中使用相對URL,是否正確?你確定肯定有數據要返回嗎?什麼是狀態碼? – thedoctor 2015-02-06 11:55:36
@thedoctor我使用郵遞員,它返回了一個JSON,除了我的集合之外的所有屬性。如果我用console.log()打印,它返回null。我沒有任何錯誤 – 2015-02-06 12:22:28
您是否嘗試在您的get方法中添加@ResponseBody註釋? – thedoctor 2015-02-06 12:29:04