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);
    }
}
复制代码

 

posted @   donleo123  阅读(3868)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示