我想显示最近的50 Tweets
。
所有其他信息,如用户名,文本或日期都可以正常工作。只能显示作者的image
。
当我运行代码段searchResults.getTweets().get(0).getProfileImageUrl()
时,它会返回一个有效的源链接,例如http://pbs.twimg.com/profile_images/..._normal.jpg
。
但是当我想在HTML
文件中显示这些图片时,它们会被破坏而无法显示。
HTML:
<html>
<head>
<title>Hello Twitter</title>
</head>
<body>
<h4>These are your results:</h4>
<table>
<tr>
<th>User</th>
<th>Image</th>
<th>Date</th>
<th>Text</th>
</tr>
<th:block th:each="tweet:${searchResults.tweets}">
<tr>
<td th:text="${tweet.fromUser}"></td> //works fine
<td><img src="${tweet.profileImageUrl}"></img></td>//doesn't work
<td th:text="${tweet.createdAt}">...</td> //works fine
<td th:text="${tweet.text}">...</td> //works fine
</tr>
</th:block>
</table>
</body>
</html>
控制器:
@RequestMapping(value = "/searchTag", method = RequestMethod.POST)
public String searchTags(Model model, @RequestParam(value = "tag") String tag) {
if (connectionRepository.findPrimaryConnection(Twitter.class) == null) {
return "redirect:/connect/twitter";
}
SearchResults searchResults = twitter.searchOperations().search(tag);
model.addAttribute("searchResults", searchResults);
return "searchResults";
}
Tweet.class:
/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.twitter.api;
import java.io.Serializable;
import java.util.Date;
/**
* Represents a Twitter status update (e.g., a "tweet").
* @author Craig Walls
*/
public class Tweet extends TwitterObject implements Serializable {
private static final long serialVersionUID = 1L;
private final long id;
private final String idStr;
private final String text;
private final Date createdAt;
private String fromUser;
private String profileImageUrl; //looking for this attribute