Compare commits
3
Commits
6a4e0e6f55
...
dd63e74094
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd63e74094 | ||
|
|
7989236859 | ||
|
|
d9a7f399fb |
@@ -0,0 +1,6 @@
|
||||
package cn.hezhaohui.thumb.constent;
|
||||
|
||||
public class UserConstant {
|
||||
|
||||
public static final String LOGIN_USER = "login_user";
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cn.hezhaohui.thumb.controller;
|
||||
|
||||
import cn.hezhaohui.thumb.common.BaseResponse;
|
||||
import cn.hezhaohui.thumb.common.ResultUtils;
|
||||
import cn.hezhaohui.thumb.constent.UserConstant;
|
||||
import cn.hezhaohui.thumb.model.entity.User;
|
||||
import cn.hezhaohui.thumb.service.UserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("user")
|
||||
public class UserController {
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@GetMapping("/login")
|
||||
public BaseResponse<User> login(long userId, HttpServletRequest request) {
|
||||
User user = userService.getById(userId);
|
||||
request.getSession().setAttribute(UserConstant.LOGIN_USER, user);
|
||||
return ResultUtils.sucess(user);
|
||||
}
|
||||
|
||||
@GetMapping("/get/login")
|
||||
public BaseResponse<User> getLoginUser(HttpServletRequest request) {
|
||||
return ResultUtils.sucess(userService.getLoginUser(request));
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class Blog {
|
||||
/**
|
||||
* 封面
|
||||
*/
|
||||
private String coverimg;
|
||||
private String coverImg;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
@@ -42,15 +42,15 @@ public class Blog {
|
||||
/**
|
||||
* 点赞数
|
||||
*/
|
||||
private Integer thumbcount;
|
||||
private Integer thumbCount;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createtime;
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updatetime;
|
||||
private Date updateTime;
|
||||
}
|
||||
@@ -27,10 +27,10 @@ public class Thumb {
|
||||
/**
|
||||
* 博客 id
|
||||
*/
|
||||
private Long blogid;
|
||||
private Long blogId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createtime;
|
||||
private Date createTime;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package cn.hezhaohui.thumb.service;
|
||||
|
||||
import cn.hezhaohui.thumb.model.entity.User;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* @author 23117
|
||||
@@ -10,4 +11,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface UserService extends IService<User> {
|
||||
|
||||
public User getLoginUser(HttpServletRequest request);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package cn.hezhaohui.thumb.service.impl;
|
||||
|
||||
import cn.hezhaohui.thumb.constent.UserConstant;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.hezhaohui.thumb.model.entity.User;
|
||||
import cn.hezhaohui.thumb.service.UserService;
|
||||
import cn.hezhaohui.thumb.mapper.UserMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -15,6 +17,11 @@ import org.springframework.stereotype.Service;
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
||||
implements UserService{
|
||||
|
||||
|
||||
@Override
|
||||
public User getLoginUser(HttpServletRequest request) {
|
||||
return (User) request.getSession().getAttribute(UserConstant.LOGIN_USER);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user