Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="user-avatar">
- <a href="/user/${vo.user.id}">
- <img width="32" class="img-circle" th:src="${vo.user.headUrl}">
- </a>
- </div>
- private String headUrl;
- public User() {}
- public User(String name) {
- this.name = name;
- this.password = "";
- this.salt = "";
- this.headUrl = "";
- }
- public String getHeadUrl() {
- return headUrl;
- }
- public void setHeadUrl(String headUrl) {
- this.headUrl = headUrl;
- }
- @Test
- public void contextLoads() {
- Random random = new Random();
- for (int i = 1; i < 10; i++) {
- User user = new User();
- user.setHeadUrl(String.format("http://images.nowcoder.com/head/%dt.png", random.nextInt(100)));
- user.setName(String.format("USER%d", i));
- user.setPassword(String.format("PASSWORD--%d",i*i));
- user.setSalt(String.format("SALT %d HelloWorld",i*5+20));
- userDao.addUser(user);
- }
- }
- @RequestMapping(path = {"/", "/index"}, method = {RequestMethod.GET,RequestMethod.POST})
- public String index(Model model){
- List<News> newsList = newsService.getLatesNews(0, 0,10);
- List<Map> vos = new ArrayList<>();
- for(News news :newsList){
- Map<String, Object> vo = new HashMap<String, Object>();
- vo.put("news",news);
- vo.put("user", userService.getUser(news.getUserId()));
- vos.add(vo);
- }
- model.addAttribute("vos", vos);
- return "home.html";
- }
- public class UserService {
- @Autowired
- private UserDao userDao;
- public User getUser(int id)
- return userDao.selectById(id);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement