首页 > 其他分享 >统一返回结果的对象

统一返回结果的对象

时间:2024-02-22 17:36:42浏览次数:13  
标签:返回 code 对象 responseResult ResponseResult static msg public 统一

其实就是一个普通的类,然后定义几个static静态方法,这样就直接调用该类的static方法。

 

package org.ongoal.common;

import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
@Data
@Slf4j
@Accessors(chain = true)
public class ResponseResult implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer code;

    private String msg;

    private Object data;

    public static ResponseResult success(int code,String msg,Object data){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(code).setMsg(msg).setData(data);
        return responseResult;
    }

    public static ResponseResult success(Object data){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(200).setMsg("").setData(data);
        return responseResult;
    }

    public static ResponseResult success(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(200).setMsg("请求成功").setData(null);
        return responseResult;
    }

    public static ResponseResult success(int code,String msg){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(code).setMsg(msg).setData(null);
        return responseResult;
    }



    public static ResponseResult fail(int code,String msg,Object data){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(code).setMsg(msg).setData(data);
        return responseResult;
    }


    public static ResponseResult fail(int code,String msg){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(code).setMsg(msg).setData(null);
        return responseResult;
    }

    public static ResponseResult fail(){
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(-1).setMsg("请求失败").setData(null);
        return responseResult;
    }

}

 

标签:返回,code,对象,responseResult,ResponseResult,static,msg,public,统一
From: https://www.cnblogs.com/qwg-/p/18027805

相关文章

  • 对象序列化内存占用问题
     一般而言,前端发起一个查询,后端接收请求而后去数据库检索并得到结果集,之后序列化为字符串返回给前端展示。在序列化方法接收一个集合到序列化(比如这里是json)的过程中,内存占用会增大吗?肯定会的,总体而言我们new出的对象,对象引用的字符、数字等都是存放在堆内存中;未序列化这些对......
  • vue中花括号表达式,string类型除以number类型返回NaN值
    bug:数据为0时,el-progress的color还是有颜色,应该是没有颜色的第一步解决:设置动态color<el-progress:show-text="false":percentage="(oilCarOccupationNum/totalNum)*100":color="oilCarOccupationNum?'......
  • 协变返回类型(covariant return type)
    协变返回类型(covariantreturntype)C++中的协变返回类型(covariantreturntype)是指派生类(子类)中的虚函数返回类型可以是基类(父类)中虚函数返回类型的子类。这个特性使得在派生类中可以返回更具体的类型,而不违反了虚函数的约定。在C++11中,如果派生类的虚函数覆盖基类的虚函数,并......
  • 函数对象
    函数对象1.什么是函数对象​ 1.类中重载了(),这个类实例化的对象叫函数对象(仿函数);​ 2.一元仿函数是operator()中只需要一个参数。二元仿函数是operator()中需要二个参数2.有什么用​ 1.做为算法的策略voidtest(){ vector<int>v; v.push_back(8); v.push_back(1); v.......
  • 【C++】编写一个具有老式风格接口的函数,其原型如下:int reduce(long arr[], int n)。实
    #include<iostream>#include<string>usingnamespacestd;intreduce(longarr[],intn){sort(arr,arr+n);autostr=unique(arr,arr+n);returnstr-arr;}intmain(){longarr[10]={15,8,5,6,11,11,6,6,198,50};......
  • 承前启后,Java对象内存布局和对象头
    承前启后,Java对象内存布局和对象头大家好,我是小高先生。在我之前的一篇文章《并发编程防御装-锁(基础版)》中,我简要介绍了锁的基础知识,并解释了为什么Java中的任何对象都可以作为锁。在那里,我提到了对象头中有一个指向ObjectMonitor的指针,但没有深入探讨Java对象的内存结构。本文将......
  • 验证对象和map赋值一样,多个方法赋值,只要中间没有重新new对象,值就会一直存在
    packageservice;importbase.BaseSpringTest;importcom.bestpay.settle.unity.certify.integration.model.CertifyInfoBO;importlombok.extern.log4j.Log4j2;importorg.junit.Test;importjava.util.HashMap;importjava.util.Map;/***场景测试类**@authorzhangkuankuan......
  • 前端处理后端返回datetime类型 格式转换
    有时候后端使用的字段为datetime,接口返回数据会变成/Date(1708311728230+0800)/这种,这时候就需要去转换一下格式functionconvertDateString(dateString){vartimestamp=parseInt(dateString.match(/\d+/)[0]);vartimezoneOffset=parseInt(dateString.match(/[......
  • 面向对象编程
    1.对象面向对象与面向过程1)两者都是一种编程思想2)面向对象强调的是事情的结果,我们通过对象完成对应的功能3)面向过程强调的是事情的过程,我们做任何事情,都要亲力亲为,经过每一个过程4)Java是一门面向对象的语言类与对象1)定义类通过关键字class来定义,类是一类事物的抽......
  • 关于ios手机Date对象的时间格式兼容问题
    通常后台返回给前端的字符串的时间数据格式是这样的:2019-8-512:18:35,要计算日期的时候需要把日期转换成时间戳才方便计算。在安卓chrome等浏览器,此格式可以直接传入到newDate(date)里,获取对应的日期,然后调用getTime方法,既可以获得相应时间的时间戳,像这样:letdate='2019-8......