2 回答

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
當(dāng)您使用 向 List 添加元素時(shí)Arrays.asList,它會(huì)創(chuàng)建作為輸入?yún)?shù)傳遞的元素列表,而不是 的 List SaisieAnomalieProjetVo。但是您需要先創(chuàng)建 的對(duì)象SaisieAnomalieProjetVo,然后再將其添加到列表中。
首先添加構(gòu)造函數(shù)SaisieAnomalieProjetVo如下:
public class SaisieAnomalieProjetVo extends AbstractAudited<Integer> {
private static final long serialVersionUID = 1L;
@NotNull
private int projet;
@NotNull
private Date date;
@NotNull
@NotEmpty
private String type;
@NotNull
@NotEmpty
private String reference;
private String description;
private Date dateRea;
public SaisieAnomalieProjetVo(final int project, final Date date, final Date dateRea, final String reference,
final String description, final String type) {
this.projet = project;
this.date = date;
this.dateRea = dateRea;
this.reference = reference;
this.description = description;
this.type = type;
}
}
然后在添加到列表創(chuàng)建對(duì)象之前SaisieAnomalieProjetVo,如下所示(假設(shè)日期格式為"yyyy/MM/dd":
final SimpleDateFormat parser= new SimpleDateFormat("yyyy/MM/dd");
final List<SaisieAnomalieProjetVo> project1 = new ArrayList(Arrays.asList(
new SaisieAnomalieProjetVo(777, parser.parse("2019/01/01"), parser.parse("2020/01/01"), "test", "test", "test")));

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超8個(gè)贊
好的,我找到了我的問題,列表顯示如我所愿。
final List<SaisieAnomalieProjetVo> project1 = new ArrayList<>(Arrays.asList(new SaisieAnomalieProjetVo(parser.parse("2019-01-01"), 777, "test", "test", "test", parser.parse("2020-01-01"))));
final List<SaisieAnomalieProjetVo> project2 = new ArrayList<>(Arrays.asList(new SaisieAnomalieProjetVo(parser.parse("2019-09-28"), 778, "test2", "test2", "test2", parser.parse("2020-01-01"))));
final List<SaisieAnomalieProjetVo> projet = new ArrayList<SaisieAnomalieProjetVo>();
projet.addAll(project2);
projet.addAll(project1);
returnData.setListAnomalies(projet);
我創(chuàng)建了構(gòu)造函數(shù),并將該構(gòu)造函數(shù)插入到一個(gè)列表中,然后創(chuàng)建了另一個(gè)“projet”列表,并再次插入了所有“projet”。然后我返回“ListAnomalies”列表
添加回答
舉報(bào)