UserController.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package com.example.onlinejudge.controller;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import cn.dev33.satoken.util.SaResult;
  4. import com.example.onlinejudge.model.entity.result.Result;
  5. import com.example.onlinejudge.service.UserService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.web.bind.annotation.PathVariable;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.ResponseBody;
  11. /**
  12. * 用户Controller层
  13. */
  14. @Controller
  15. public class UserController {
  16. @Autowired
  17. private UserService userService;
  18. /**
  19. * 登录
  20. *
  21. * @param username 用户名
  22. * @param password 用户密码
  23. * @return 用户bean
  24. */
  25. @RequestMapping("/api/login/{username}/{password}")
  26. @ResponseBody
  27. public Result login(@PathVariable("username") String username,
  28. @PathVariable("password") String password) {
  29. return userService.login(username, password);
  30. }
  31. /**
  32. * 测试是否登录
  33. *
  34. * @return 字符串
  35. */
  36. @RequestMapping("/api/isLogin")
  37. @ResponseBody
  38. public String isLogin() {
  39. return "当前会话登录了";
  40. }
  41. /**
  42. * 测试注销
  43. * @return LinkedHashMap
  44. */
  45. @RequestMapping("/api/logout")
  46. @ResponseBody
  47. public Result logout() {
  48. StpUtil.logout();
  49. return Result.success();
  50. }
  51. }