为什么相同的代码在servlet中工作但在Spring控制器中不起作用?

时间:2011-02-17 22:29:01

标签: java spring spring-mvc gdata picasa

此代码在servlet中运行:

PicasawebService service = new PicasawebService("Picasa test");
PicasawebClient picasaClient = new PicasawebClient(service);
List<AlbumEntry> albums = picasaClient.getAlbums("cgcmh1@gmail.com");
for(AlbumEntry album: albums){
    resp.getWriter().println(album.getTitle().getPlainText());
    List<PhotoEntry> photos = picasaClient.getPhotos(album);
    req.setAttribute("photos", photos);
}

所以我尝试使用model.addAttribute(下面)而不是req.setAttribute(上面)将它放在Spring控制器中:

PicasawebService service = new PicasawebService("Picasa test");
PicasawebClient picasaClient = new PicasawebClient(service);
List<AlbumEntry> albums = picasaClient.getAlbums("cgcmh1@gmail.com");
for (AlbumEntry album : albums){
    logger.warn("albums:" + album.getTitle().getPlainText());
    List<PhotoEntry> photos = picasaClient.getPhotos(album);
    model.addAttribute("photos", photos);
}

但是,当servlet代码成功找到它们时,Spring代码无法在Picasa中找到任何相册。

任何人都知道为什么会这样吗?

在这两种情况下,他们都使用this version of the PicasawebClientthis version of the PicasawebService

1 个答案:

答案 0 :(得分:0)

model.addAttribute("photos", photos);

会在每次迭代时覆盖地图的photos属性,因此您只能访问上一个专辑。