ViewController.java 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package com.sso.vip.controller;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.stereotype.Controller;
  4. import org.springframework.web.bind.annotation.CookieValue;
  5. import org.springframework.web.bind.annotation.GetMapping;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import org.springframework.web.client.RestTemplate;
  8. import org.thymeleaf.util.StringUtils;
  9. import javax.servlet.http.Cookie;
  10. import javax.servlet.http.HttpSession;
  11. import java.util.Map;
  12. @Controller
  13. @RequestMapping("/view")
  14. public class ViewController {
  15. @Autowired
  16. private RestTemplate restTemplate;
  17. private final String USER_INFO_ADDRESS = "http://login.codeshop.com:9000/login/info?token=";
  18. @GetMapping("/index")
  19. public String toIndex(@CookieValue(required = false,value = "TOKEN")Cookie cookie,
  20. HttpSession session){
  21. if (cookie != null){
  22. String token = cookie.getValue();
  23. if(!StringUtils.isEmpty(token)){
  24. Map result = restTemplate.getForObject(USER_INFO_ADDRESS + token, Map.class);
  25. session.setAttribute("loginUser",result);
  26. }
  27. }
  28. return "index";
  29. }
  30. }