如果我犯了错误,请忽略任何初学者错误。以下是我的问题:
我有一个课程项目:
@Entity
@JsonIgnoreProperties(ignoreUnknown = true)
@Table(name = "item")
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
//@ManyToOne
private Long id;
private String stream_item_key;
private String stream_item_date;
private String channel;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "item_workflow", joinColumns = @JoinColumn(name = "item_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "workflow_id", referencedColumnName = "id"))
private List<Workflow> workflow;
工作流是另一个类,Workflow具有以下类成员:
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String actor;
private String assignee;
private String date;
private String team;
private String action;
我已经使用JPA加入项目和工作流程,我能够看到完整的数据提取。但是,在另一种方法中,我只想提取Item.stream_item_date, Workflow.Actor and Workflow.date
我可以使用Item.stream_item_date
访问器提取getStream_item_date()
,但我不确定如何访问List元素。我研究过Stackoverflow,我找不到任何答案,所有这些都导致更新索引和其他东西。我不确定这是否是正确的方法?
提前感谢您的回答!
答案 0 :(得分:0)
感谢您的回答@JB Nizet
Item items = this.getQueryOne();
// getQueryOne() returns the Item object
for (Workflow workflow: items.getWorkflow()) {
System.out.println(workflow.getActor());
System.out.println(workflow.getDate());
}
答案 1 :(得分:-1)
for(Iterator<?>ui=Item.getWorkflow().iterator()ui.hasNext();){
Workflow temp= (Workflow) ui.next();
System.out.print(temp.getActor()); }