AlbumService albumService=new AlbumServiceImpl();
List albumList= albumService.getAlbumsByUserId(user.getUserId());
for(Album album :albumList){
PhotoService photoService =new PhotoServiceImpl();
List photos=photoService.getPhotosByAlbumId(album.getAlbumId());
int count=photoService.getCountByAlbumId(album.getAlbumId());
request.setAttribute("photos"+album.getAlbumId(),photos);
}
request.setAttribute("albumList",albumList);
public class AlbumVO {
private Integer albumId;
private String albumName;
private Integer userId;
private String introduce;
private Integer count;
private List photos;
//get和set方法省略了
}
后台
AlbumService albumService=new AlbumServiceImpl();
List albumList= albumService.getAlbumsByUserId(user.getUserId());
System.out.println(albumList);
List albumVOS=new ArrayList<>();
//这里可以用jdk1.7以后的类拷贝,可以少些代码
for(Album album :albumList){
AlbumVO albumVO=new AlbumVO();
albumVO.setAlbumId(album.getAlbumId());
albumVO.setAlbumName(album.getAlbumName());
albumVO.setIntroduce(album.getIntroduce());
albumVO.setUserId(album.getUserId());
PhotoService photoService =new PhotoServiceImpl();
List photos=photoService.getPhotosByAlbumId(album.getAlbumId());
int count=photoService.getCountByAlbumId(album.getAlbumId());
albumVO.setPhotos(photos);
albumVO.setCount(count);
albumVOS.add(albumVO);
//request.setAttribute("photos"+album.getAlbumId(),photos);
}
request.setAttribute("albumList",albumVOS);
jstl的foreach标签items直接写album.photos就行了
即实现了foreach嵌套循环
${album.albumName}(${album.introduce})