Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. <div class="user-avatar">
  2. <a href="/user/${vo.user.id}">
  3. <img width="32" class="img-circle" th:src="${vo.user.headUrl}">
  4. </a>
  5. </div>
  6.  
  7. private String headUrl;
  8.  
  9. public User() {}
  10.  
  11. public User(String name) {
  12. this.name = name;
  13. this.password = "";
  14. this.salt = "";
  15. this.headUrl = "";
  16. }
  17.  
  18. public String getHeadUrl() {
  19. return headUrl;
  20. }
  21.  
  22. public void setHeadUrl(String headUrl) {
  23. this.headUrl = headUrl;
  24. }
  25.  
  26. @Test
  27. public void contextLoads() {
  28. Random random = new Random();
  29. for (int i = 1; i < 10; i++) {
  30. User user = new User();
  31. user.setHeadUrl(String.format("http://images.nowcoder.com/head/%dt.png", random.nextInt(100)));
  32. user.setName(String.format("USER%d", i));
  33. user.setPassword(String.format("PASSWORD--%d",i*i));
  34. user.setSalt(String.format("SALT %d HelloWorld",i*5+20));
  35. userDao.addUser(user);
  36. }
  37. }
  38.  
  39. @RequestMapping(path = {"/", "/index"}, method = {RequestMethod.GET,RequestMethod.POST})
  40. public String index(Model model){
  41. List<News> newsList = newsService.getLatesNews(0, 0,10);
  42.  
  43. List<Map> vos = new ArrayList<>();
  44. for(News news :newsList){
  45. Map<String, Object> vo = new HashMap<String, Object>();
  46. vo.put("news",news);
  47. vo.put("user", userService.getUser(news.getUserId()));
  48. vos.add(vo);
  49. }
  50.  
  51. model.addAttribute("vos", vos);
  52. return "home.html";
  53. }
  54.  
  55. public class UserService {
  56. @Autowired
  57. private UserDao userDao;
  58.  
  59. public User getUser(int id)
  60. return userDao.selectById(id);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement