springboot+vue+mybatisplus项目实战-学生成绩管理系统08

661 篇文章 4 订阅
112 篇文章 0 订阅

contants

mycontants.java

package com.shrimpking.constants;

import java.nio.charset.StandardCharsets;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/11/4 22:37
 * 自定义常量类
 */
public interface MyConstants
{
    /**
     * token的key名称
     */
    String USER_TOKEN_KEY = "user_token";
    /**
     *
     */
    String UTF_8_NAME = StandardCharsets.UTF_8.name();
    /**
     * 默认,当前页
     */
    Long DEFAULT_CURRENT_PAGE = 1L;
    /**
     * 默认,页条数
     */
    Long DEFAULT_PAGE_SIZE = 10L;
}

context

UserContext.java

package com.shrimpking.context;

import com.shrimpking.dto.UserDTO;
import com.shrimpking.pojo.User;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/11/5 10:03
 */
public class UserContext
{
    private static ThreadLocal<UserDTO> threadLocal = new ThreadLocal<>();

    /**
     * 保存至线程中
     * @param userDTO
     */
    public static void set(UserDTO userDTO){
        threadLocal.set(userDTO);
    }

    /**
     * 从线程中获取
     * @return
     */
    public static UserDTO get(){
        return threadLocal.get();
    }

    /**
     * 从线程中移除
     */
    public static void remove(){
        threadLocal.remove();
    }

}

dto

userdto.java

package com.shrimpking.dto;

import lombok.Data;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/11/4 17:14
 * 定义了token中包含的哪些信息
 */
@Data
public class UserDTO
{
    private Long id;
    private String userName;
}

enums

codeEnum.java

package com.shrimpking.enums;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Shrimpking
 * @create 2023/11/4 18:18
 * 响应码枚举类
 */
public enum  CodeEnum
{
    /**
     * 成功
     */
    SUCCESS(200,"成功"),
    /**
     * 失败
     */
    ERROR(500,"失败"),
    /**
     * 其他失败
     */
    PARAM_ERROR(510,"参数不正确"),

    AUTH_ERROR(520,"权限不足"),

    DB_ERROR(530,"数据库异常"),

    DUPLICATE_KEY_ERROR(550,"唯一键约束重复"),

    BIZ_ERROR(570,"业务异常"),

    OTHER_ERROR(599,"其他异常"),

    ;

    CodeEnum(Integer code,String msg){
        this.code = code;
        this.msg = msg;
    }

    private Integer code;
    private String msg;

    public Integer getCode()
    {
        return code;
    }

    public void setCode(Integer code)
    {
        this.code = code;
    }

    public String getMsg()
    {
        return msg;
    }

    public void setMsg(String msg)
    {
        this.msg = msg;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虾米大王

有你的支持,我会更有动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值