Java后端开发——返回值类型实体代码示例

package com.xolo.core.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
public class GroupEasyWechatResponse {

    @ApiModelProperty("用户组名")
    private String groupName;

    @ApiModelProperty("组员名称")
    private String memberName;

    @ApiModelProperty("组员数量")
    private Integer groupMemberTotal;

    @ApiModelProperty("归属微信号")
    private List<WechatResponse> wechatResponseList;
}

 

复合返回值类型wechatResponseList如下:

package com.xolo.core.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class WechatResponse {

    @ApiModelProperty("微信号")
    private String wechat;

    @ApiModelProperty("微信二维码")
    private String wechatQrcode;
}

 

假设要返回时间代码如下:

@ApiModelProperty("绑定时间")
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")  //更改时区,避免返回的时间与北京时间相差8小时
    private Date bindTime;

 

一般的Response代码如下:

package com.xolo.core.response;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class Response<T> {

    final static public String SUCCESS_CODE = "200"; // 请求成功返回结果码
    final static public String FAIl_CODE = "500";   // 请求失败返回结果码

    @ApiModelProperty("返回消息描述")
    private String message;

    @ApiModelProperty("返回结果码")
    private String code;

    @ApiModelProperty("返回数据")
    private T data;

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    // 请求成功构造函数
    public Response(String message, String code, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 请求失败构造函数
    public Response(String message) {
        this.message = message;
        this.code = FAIl_CODE;
    }
}

 

扫码关注公众号,查看更多精彩内容

posted @ 2020-03-12 22:42  不是公子的小白  阅读(1420)  评论(0编辑  收藏  举报