This commit is contained in:
苏元皓
2024-08-09 09:27:23 +08:00
parent 946c479d04
commit a018f5b85d
54 changed files with 2794 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
package com.ivmiku.tutorial.controller;
import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson2.JSON;
import com.ivmiku.tutorial.response.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
@RestController
@RequestMapping("/test")
public class TestController {
@GetMapping("/login1")
public Object getToken1() {
StpUtil.login("1");
String token = StpUtil.getTokenValue();
HashMap<String, Object> map = new HashMap<>();
map.put("token", token);
return JSON.toJSON(Result.ok(map));
}
@GetMapping("/login2")
public Object getToken2() {
StpUtil.login("2");
String token = StpUtil.getTokenValue();
HashMap<String, Object> map = new HashMap<>();
map.put("token", token);
return JSON.toJSON(Result.ok(map));
}
@PostMapping("test")
public Object test() {
//添加请求头"satoken"值为上方接口返回的token后可以获取token对应的用户id
String userId = (String) StpUtil.getLoginId();
//其他业务逻辑
return Result.ok();
}
}