• 自定义http状态码


    CodeMsg类

    package cma.sxqxgxw.utils.result;
    
    public class CodeMsg {
        private int code;
        private String msg;
    
        //通用的错误码
        public static CodeMsg SUCCESS = new CodeMsg(0, "success");
        public static CodeMsg TOKEN_EXPIRED = new CodeMsg(400, "token过期");
        public static CodeMsg TOKEN_INVALID = new CodeMsg(401, "token解析异常");
        public static CodeMsg USER_NOT_LOGGED_IN = new CodeMsg(402, "未登录,请登录!");
        public static CodeMsg SIGNATURE_ERROR = new CodeMsg(506, "签名失败");
        public static CodeMsg SERVER_ERROR = new CodeMsg(500, "服务端异常");
        public static CodeMsg FILE_ERROR = new CodeMsg(501, "文件不存在");
        public static CodeMsg FILE_EXIST = new CodeMsg(5012, "文件已存在");
        public static CodeMsg TIME_ERROR = new CodeMsg(502, "时间格式错误,应为 yyyy-MM-dd HH:mm:ss");
        public static CodeMsg TIMEMISS_ERROR = new CodeMsg(503, "查询时间缺失,应为 yyyy-MM-dd HH:mm:ss");
        public static CodeMsg BIND_ERROR = new CodeMsg(504, "参数绑定异常");
        public static CodeMsg CONTROL_ERROR = new CodeMsg(505, "请检查参数是否缺失,输入是否正确");
        public static CodeMsg BINDING_FAILED = new CodeMsg(506, "绑定失败");
        public static CodeMsg UNBIND_FAILED = new CodeMsg(507, "解绑失败");
    
        // user:  1000 - 1100
        public static CodeMsg USER_PWD_ERROR = new CodeMsg(1001,"密码错误,请重新输入!");
        public static CodeMsg USER_NAME_ERROR = new CodeMsg(1002,"用户名不存在,请注册!");
        public static CodeMsg USER_NAME_EXIST_ERROR = new CodeMsg(1003, "用户名已存在");
        public static CodeMsg USER_PWD_FORMAT_ERROR = new CodeMsg(1004, "密码是由8至16位的数字和字母组成,请重新输入");
    
        // apply order:  1100 - 1200
        public static CodeMsg ORDER_NOT_EXIST = new CodeMsg(1101,"非本人申请单或申请单不存在!");
        public static CodeMsg ORDER_CANCELED = new CodeMsg(1102,"申请单已被撤销!");
        public static CodeMsg ORDER_REJECTED = new CodeMsg(1103, "申请已被驳回!");
        public static CodeMsg ORDER_AUDITED = new CodeMsg(1104, "申请单已被审核!");
        public static CodeMsg ORDER_ACCEPTED_CAN_NOT_CANCELED = new CodeMsg(1105, "申请单已被处理,不能撤销!");
        public static CodeMsg ORDER_NOT_AUDITED = new CodeMsg(1106, "当前申请单未被审核通过!");
        public static CodeMsg ORDER_TIME_FORMAT = new CodeMsg(1107, "时间范围输入错误,正确格式为[yyyyMMddHHmmss,yyyyMMddHHmmss]");
        public static CodeMsg ORDER_AUDITRESULT = new CodeMsg(1108, "请输入正确的auditResult!");
        public static CodeMsg ORDER_AUDITED_FAILED = new CodeMsg(1109, "审核失败!");
        public static CodeMsg ORDER_SELECTED_FAILED = new CodeMsg(1110, "查询失败!");
        public static CodeMsg ORDER_CANCELED_FAILED = new CodeMsg(1111, "撤销失败!");
        public static CodeMsg ORDER_UPLOAD_FAILED = new CodeMsg(1112, "上传附件失败!");
        private CodeMsg() {
        }
        public CodeMsg(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }
        public int getCode() {
            return code;
        }
        public void setCode(int code) {
            this.code = code;
        }
        public String getMsg() {
            return msg;
        }
        public void setMsg(String msg) {
            this.msg = msg;
        }
        /**
         * 返回带参数的错误码
         * @param args
         * @return
         */
        public CodeMsg fillArgs(Object... args) {
            int code = this.code;
            String message = String.format(this.msg, args);
            return new CodeMsg(code, message);
        }
        @Override
        public String toString() {
            return "CodeMsg [code=" + code + ", msg=" + msg + "]";
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74

    server类

    @Override
    public Result<Object> getAllApplyOrdersByTimeRange(String timeRange, Integer page, Integer pageSize) {
        String dateString = timeRange.substring(1, timeRange.length() - 1); // 去掉中括号
        String[] dateArray = dateString.split(",");
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        Date startDate;
        Date endDate;
        try {
            startDate = format.parse(dateArray[0]);
            endDate = format.parse(dateArray[1]);
        } catch (ParseException e) {
            return Result.error(CodeMsg.ORDER_TIME_FORMAT);
        }
        //admin
        LambdaQueryWrapper<ApplyOrderDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.lt(ApplyOrderDO::getCreateTime, endDate);
        queryWrapper.gt(ApplyOrderDO::getCreateTime, startDate);
        queryWrapper.orderByDesc(ApplyOrderDO::getCreateTime);
        int pageInt = page != null && page > 0 ? page : 1;
        int pageSizeInt = pageSize != null && pageSize > 0 ? pageSize : 10;
        Page<ApplyOrderDO> pageDo = new Page<>(pageInt, pageSizeInt);
        Page<ApplyOrderDO> applyOrderDOPage = applyOrderMapper.selectPage(pageDo, queryWrapper);
        // DO 转 VO (Page对象)
        Page<ApplyOrderVO> applyOrderVOPage = ApplyOrderMapper.INSTANCE.toVOPage(applyOrderDOPage);
        return Result.success(applyOrderVOPage);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
  • 相关阅读:
    linux下安装 Chrome 和 chromedriver 以及 selenium webdriver 使用
    springboot自习室管理系统 毕业设计-附源码221535
    详细说说什么是单元测试的边界
    MySQL批量入库的几种方式详解
    使用LLama和ChatGPT为多聊天后端构建微服务
    数仓模型设计方法论
    【从0开始学架构】访问层架构设计
    2.如何选择go语言基础类型——Leetcode习题9
    【深度学习】第四章:循环神经网络
    FFmpeg 硬件加速介绍
  • 原文地址:https://blog.csdn.net/weixin_43732943/article/details/132733861