123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package com.example.onlinejudge.controller;
- import cn.dev33.satoken.stp.StpUtil;
- import cn.dev33.satoken.util.SaResult;
- import com.example.onlinejudge.model.entity.result.Result;
- import com.example.onlinejudge.service.UserService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- /**
- * 用户Controller层
- */
- @Controller
- public class UserController {
- @Autowired
- private UserService userService;
- /**
- * 登录
- *
- * @param username 用户名
- * @param password 用户密码
- * @return 用户bean
- */
- @RequestMapping("/api/login/{username}/{password}")
- @ResponseBody
- public Result login(@PathVariable("username") String username,
- @PathVariable("password") String password) {
- return userService.login(username, password);
- }
- /**
- * 测试是否登录
- *
- * @return 字符串
- */
- @RequestMapping("/api/isLogin")
- @ResponseBody
- public String isLogin() {
- return "当前会话登录了";
- }
- /**
- * 测试注销
- * @return LinkedHashMap
- */
- @RequestMapping("/api/logout")
- @ResponseBody
- public Result logout() {
- StpUtil.logout();
- return Result.success();
- }
- }
|