仓库2
parent
af0693756e
commit
830ade4219
|
@ -1,11 +1,15 @@
|
|||
package com.muyu.market.server.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.JwtUtils;
|
||||
import com.muyu.market.admain.SysUser;
|
||||
import com.muyu.market.server.service.SysUserService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
@ -13,16 +17,25 @@ import org.springframework.web.bind.annotation.*;
|
|||
@RequestMapping("/sysUser")
|
||||
@Tag( name = "个人信息控制层",description = "用于操作用户个人信息")
|
||||
public class SysUserController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@PostMapping("/findById")
|
||||
@Operation(summary = "显示用户信息",description = "显示用户基本信息")
|
||||
public Result<SysUser> findById(@RequestParam(value = "userId") Integer userId){
|
||||
SysUser byId = sysUserService.getById( userId );
|
||||
public Result<SysUser> findById(){
|
||||
//获取请求头Token
|
||||
String token = request.getHeader( "token" );
|
||||
//转userkey
|
||||
String userKey = JwtUtils.getUserKey( token );
|
||||
//通过key名字和Token取值
|
||||
String s = redisTemplate.opsForValue().get( "token:" + userKey );
|
||||
//转实体类类型
|
||||
SysUser user = JSONObject.parseObject( s, SysUser.class );
|
||||
SysUser byId = sysUserService.getById( user.getUserId() );
|
||||
return Result.success(byId);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue