为什么相同的代码在 servlet 中可以工作,但在 Spring 控制器中却不行?
这段代码在 servlet 中工作:
PicasawebService service = new PicasawebService("Picasa test");
PicasawebClient picasaClient = new PicasawebClient(service);
List<AlbumEntry> albums = picasaClient.getAlbums("[email protected]");
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("[email protected]");
for (AlbumEntry album : albums){
logger.warn("albums:" + album.getTitle().getPlainText());
List<PhotoEntry> photos = picasaClient.getPhotos(album);
model.addAttribute("photos", photos);
}
但是, Spring 代码无法在 Picasa 中找到任何相册,而 servlet 代码可以成功找到它们。
有谁知道为什么会这样?
在这两种情况下,他们都使用 此版本的 PicasawebClient 和 此版本的 PicasawebService。
This code works in a servlet:
PicasawebService service = new PicasawebService("Picasa test");
PicasawebClient picasaClient = new PicasawebClient(service);
List<AlbumEntry> albums = picasaClient.getAlbums("[email protected]");
for(AlbumEntry album: albums){
resp.getWriter().println(album.getTitle().getPlainText());
List<PhotoEntry> photos = picasaClient.getPhotos(album);
req.setAttribute("photos", photos);
}
So I tried putting it in a Spring controller by using model.addAttribute
(below) instead of req.setAttribute
(above):
PicasawebService service = new PicasawebService("Picasa test");
PicasawebClient picasaClient = new PicasawebClient(service);
List<AlbumEntry> albums = picasaClient.getAlbums("[email protected]");
for (AlbumEntry album : albums){
logger.warn("albums:" + album.getTitle().getPlainText());
List<PhotoEntry> photos = picasaClient.getPhotos(album);
model.addAttribute("photos", photos);
}
However, the Spring code fails to find any albums in Picasa while the servlet code finds them successfully.
Anyone know why this is the case?
In both cases they are using this version of the PicasawebClient and this version of the PicasawebService.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将在每次迭代时覆盖地图的
photos
属性,因此您只能访问最后一个相册。will override the
photos
attribute of the map on each iteration, so you will only be able to access the last album.