我有双向关系。 这是我实体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