zoukankan      html  css  js  c++  java
  • layUI框架table.render发送请求,数据返回格式封装

    1、状态码枚举类

    package com.donleo.ssm.utils;
    
    /**
     * @author liangd
     * date 2020-11-22 16:51
     * code
     */
    public enum ResponseLayCode {
        //成功状态码
        SUCCESS(0),
        //空值状态码
        NULL(1);
    
        private int code;
    
        ResponseLayCode(int code) {
            this.code = code;
        }
    
        public int getCode() {
            return code;
        }
    
        public void setCode(int code) {
            this.code = code;
        }
    }

    2、返回格式封装类

    package com.donleo.ssm.utils;
    
    /**
     * @author liangd
     * date 2020-11-22 16:41
     * code LayUI 返回格式数据工具类
     */
    public class ResponseLayResult<T> {
        /**
         * 返回状态码
         */
        private int code;
        /**
         * 总条数
         */
        private long count;
        /**
         * 提示信息
         */
        private String msg;
        /**
         * 返回数据
         */
        private T data;
    
        /**
         * 有数据构造方法
         */
        private ResponseLayResult(int code, long count, T data) {
            this.code = code;
            this.count = count;
            this.data = data;
        }
    
        /**
         * 空值构造方法
         */
        private ResponseLayResult(int code, long count, String msg) {
            this.code = code;
            this.count = count;
            this.msg = msg;
        }
    
        /**
         * getter/setter 方法
         */
        public int getCode() {
            return code;
        }
    
        public void setCode(int code) {
            this.code = code;
        }
    
        public long getCount() {
            return count;
        }
    
        public void setCount(long count) {
            this.count = count;
        }
    
        public String getMsg() {
            return msg;
        }
    
        public void setMsg(String msg) {
            this.msg = msg;
        }
    
        public T getData() {
            return data;
        }
    
        public void setData(T data) {
            this.data = data;
        }
    
        /**
         * 返回有数据信息
         */
        public static <T> ResponseLayResult<T> createBySuccess(long count, T data) {
            return new ResponseLayResult<T>(ResponseLayCode.SUCCESS.getCode(), count, data);
        }
    
        /**
         * 返回空数据信息
         */
        public static <T> ResponseLayResult<T> createByNull(long count, String msg) {
            return new ResponseLayResult<T>(ResponseLayCode.NULL.getCode(), count, msg);
        }
    
        /**
         * 返回空数据信息(count为null)
         */
        public static <T> ResponseLayResult<T> createByNull(String msg) {
            return new ResponseLayResult<T>(ResponseLayCode.NULL.getCode(), ResponseLayCode.SUCCESS.getCode(), msg);
        }
    }
    作者:donleo123
    本文如对您有帮助,还请多推荐下此文,如有错误欢迎指正,相互学习,共同进步。
  • 相关阅读:
    Day 15 模块
    Day 14 三元运算符,列表推导式,内置函数
    Day 13 可迭代对象,迭代器对象,for循环迭代,生成器对象,枚举对象
    Day 12 开放封闭原则,装饰器初识
    Day 11 函数对象,函数嵌套,作用域,闭包
    Day 10 函数的形参,实参
    Day 09 函数基础
    Day 08 文件操作模式,文件复制,游标
    HTTP协议
    11,.JS-DOM价绍
  • 原文地址:https://www.cnblogs.com/donleo123/p/14068089.html
Copyright © 2011-2022 走看看