我有两个对象应用程序和环境列表。我正在添加这些列表,但我得到的输出是一个完整的应用程序列表,而不是另一个完整的环境列表。
我希望它采用嵌套形式,例如应用程序和环境的一个条目,而不是应用程序和环境的第二行等
这是我的代码:
@GET
@Path("/test")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ArrayList<MyModel> Test(){
System.out.println("inside test");
List<ApplicationDTO> allApplication = applicationService.getAllApplication();
List<Application> Applist = new ArrayList<Application>();
List<Environment> Envlist = new ArrayList<Environment>();
for(ApplicationDTO d: allApplication)
{
Application a = new Application();
a.setApplicationDescription(d.getApplicationDescription());
a.setApplicationId(d.getApplicationId());
a.setApplicationName(d.getApplicationName());
a.setAssignedTo(d.getAssignedTo());
a.setCreatedBy(d.getCreatedBy());
a.setCreateTime(d.getCreateTime());
a.setModifiedTime(d.getModifiedTime());
a.setOwner(d.getOwner());
Environment e = new Environment();
for(EnvironmentDTO en: d.getEnvironment())
{
e.setEnvironmentId(en.getEnvironmentId());
e.setEnvironmentName(en.getEnvironmentName());
e.setOwner(en.getOwner());
e.setCreateTime(en.getCreateTime());
Envlist.add(e);
}
Applist.add(a);
}
ArrayList<MyModel> obj= new ArrayList<MyModel>();
MyModel mm = new MyModel();
mm.setAppDTO(Applist);
mm.setEnDTO(Envlist);
obj.add(mm);
return obj;
}
编辑
我改变了我的课程,我在应用程序内添加了环境列表,现在我正在获取应用程序内所有环境的列表,但我需要一个应用程序内的一个环境,另一个在下一个应用程序内,依此类推。我错过了什么?
public List<Application> Test(){
System.out.println("inside test");
List<ApplicationDTO> allApplication = applicationService.getAllApplication();
List<Application> Applist = new ArrayList<Application>();
List<Environment> Envlist = new ArrayList<Environment>();
for(ApplicationDTO d: allApplication)
{
Application a = new Application();
a.setApplicationDescription(d.getApplicationDescription());
a.setApplicationId(d.getApplicationId());
a.setApplicationName(d.getApplicationName());
a.setAssignedTo(d.getAssignedTo());
a.setCreatedBy(d.getCreatedBy());
a.setCreateTime(d.getCreateTime());
a.setModifiedTime(d.getModifiedTime());
a.setOwner(d.getOwner());
for(EnvironmentDTO en: d.getEnvironment())
{
Environment e = new Environment();
e.setEnvironmentId(en.getEnvironmentId());
e.setEnvironmentName(en.getEnvironmentName());
e.setOwner(en.getOwner());
e.setCreateTime(en.getCreateTime());
Envlist.add(e);
}
a.setEnvlists(Envlist);
Applist.add(a);
}
return Applist;