MainController.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.izouma.awesomeadmin.web;
  2. import org.apache.shiro.SecurityUtils;
  3. import org.apache.shiro.authz.annotation.RequiresRoles;
  4. import org.apache.shiro.subject.Subject;
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.web.bind.annotation.PathVariable;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RequestMethod;
  9. import org.springframework.web.bind.annotation.ResponseBody;
  10. import org.springframework.web.servlet.ModelAndView;
  11. import javax.servlet.http.HttpServletRequest;
  12. /**
  13. * 首页
  14. * Created by xiong on 2016/10/26.
  15. */
  16. @Controller
  17. public class MainController {
  18. // @RequestMapping(value = "/index", method = RequestMethod.GET)
  19. // @ResponseBody
  20. // public ModelAndView home() {
  21. // return new ModelAndView("redirect:/admin");
  22. // }
  23. @RequestMapping("/index")
  24. public ModelAndView index(HttpServletRequest request) {
  25. return new ModelAndView("html/admin.html");
  26. }
  27. @RequestMapping("/")
  28. public ModelAndView autoIndex(HttpServletRequest request) {
  29. return new ModelAndView("html/admin.html");
  30. }
  31. @RequestMapping("/admin")
  32. public ModelAndView admin(HttpServletRequest request) {
  33. Subject subject = SecurityUtils.getSubject();
  34. if (subject.hasRole("admin")) {
  35. return new ModelAndView("html/admin.html");
  36. } else {
  37. return new ModelAndView("redirect:/loginAdmin");
  38. }
  39. }
  40. @RequestMapping("/home")
  41. public ModelAndView home(HttpServletRequest request) {
  42. return new ModelAndView("html/admin.html");
  43. }
  44. @RequestMapping("/loginAdmin")
  45. public ModelAndView loginAdmin(HttpServletRequest request) {
  46. return new ModelAndView("html/loginAdmin.html");
  47. }
  48. }