enum StatusCode

package com.lee.utils;

public enum StatusCode {
SUCCESS(20000, "成功"), FALL(50000, "失败"), REQUEST_PARAM_ERROR(50001, "请求参数错误"); private int code; private String message; StatusCode(int code, String message) {
this.code = code;
this.message = message;
} public int getCode() {
return code;
} public void setCode(int code) {
this.code = code;
} public String getMessage() {
return message;
} public void setMessage(String message) {
this.message = message;
} }

class ResultBuilder<T>

package com.lee.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import com.alibaba.fastjson.JSONObject; public class ResultBuilder<T> { public ResultBuilder(T data, int code, String message) {
this.result = data;
this.code = code;
this.message = message;
this.responseTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} public ResultBuilder(T data, StatusCode statusCode) {
this.result = data;
this.code = statusCode.getCode();
this.message = statusCode.getMessage();
this.responseTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} public ResultBuilder(T data, StatusCode statusCode, String extendMsg) {
this.result = data;
this.code = statusCode.getCode();
this.message = statusCode.getMessage() + extendMsg;
this.responseTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} public ResultBuilder(StatusCode statusCode) {
this.code = statusCode.getCode();
this.message = statusCode.getMessage();
this.responseTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} public ResultBuilder(StatusCode statusCode, String extendMsg) {
this.code = statusCode.getCode();
this.message = statusCode.getMessage() + extendMsg;
this.responseTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} public ResultBuilder(int code, String message) {
this.code = code;
this.message = message;
this.responseTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} public ResultBuilder(int code) {
this.code = code;
this.responseTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
} private int code;
private String message;
private T result;
private String responseTime; public int getCode() {
return code;
} public void setCode(int code) {
this.code = code;
} public String getMessage() {
return message;
} public void setMessage(String message) {
this.message = message;
} public T getResult() {
return result;
} public void setResult(T result) {
this.result = result;
} public String getResponseTime() {
return responseTime;
} public void setResponseTime(String responseTime) {
this.responseTime = responseTime;
} public JSONObject toJSONObject() {
JSONObject out = new JSONObject();
out.put("code", code);
out.put("message", message);
out.put("result", result);
out.put("responseTime", responseTime);
return out;
} public String toString() {
return toJSONObject().toString();
}
}

Java 数据返回接口封装的更多相关文章

  1. 【开源项目12】Retrofit – Java(Android) 的REST 接口封装类库

    Retrofit官网:http://square.github.io/retrofit/ Retrofit 和Java领域的ORM概念类似, ORM把结构化数据转换为Java对象,而Retrofit ...

  2. Retrofit – Java(Android) 的REST 接口封装类库

    Retrofit 和Java领域的ORM概念类似, ORM把结构化数据转换为Java对象,而Retrofit 把REST API返回的数据转化为Java对象方便操作.同时还封装了网络代码的调用. 例如 ...

  3. java—将查询的结果封装成List<Map>与用回调函数实现数据的动态封装(44)

    手工的开始QueryRunner类.实现数据封装: MapListHandler MapHandler BeanListHandler BeanHandler 第一步:基本的封装测试 写一个类,Que ...

  4. 基于Zabbix API文档二次开发与java接口封装

    (继续贴一篇之前工作期间写的经验案例) 一.           案例背景 我负责开发过一个平台的监控报警模块,基于zabbix实现,需要对zabbix进行二次开发. Zabbix官方提供了Rest ...

  5. java:Session(概述,三层架构实例(实现接口封装JDBC),Session实现简单购物车实例)

    1.Session概述: Session:在计算机中,尤其是在网络应用中,称为“会话控制”.Session 对象存储特定用户会话所需的属性及配置信息.这样,当用户在应用程序的 Web 页之间跳转时,存 ...

  6. spring boot 接口返回值封装

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  7. java读取PHP接口数据的实现方法(四)

    PHP文件: ? 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 3 ...

  8. 聚合数据实名认证接口-java方法

    只需要填入购买的APPKEY,然后直接调用方法JuheDemo.info(user_name, anchor_card);传入姓名和身份证号,根据获取的返回参数进行拆分,如res=1说明正确. //进 ...

  9. Java学习-013-文本文件读取实例源代码(两种数据返回格式)

    此文源码主要为应用 Java 读取文本文件内容实例的源代码.若有不足之处,敬请大神指正,不胜感激! 1.读取的文本文件内容以一维数组[LinkedList<String>]的形式返回,源代 ...

随机推荐

  1. Web项目中手机注册短信验证码实现的全流程及代码

    最近在做只能净化器的后台用户管理系统,需要使用手机号进行注册,找了许久才大致了解了手机验证码实现流程,今天在此和大家分享一下. 我们使用的是榛子云短信平台, 官网地址:http://smsow.zhe ...

  2. js 类

    ---恢复内容开始--- <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset ...

  3. linux安装jdk配置环境变量

    tar -zxvf xxxx.tar.gz export JAVA_HOME=/usr/local/jdk/jdk1.8.0_201export PATH=$JAVA_HOME/bin:$PATHex ...

  4. 19个实例学会plsql

    --p1 begin dbms_output.put_line('你好 世界'); end; --p2 引入变量 declare age ; height ; begin dbms_output.pu ...

  5. Spring IOC原理解读 面试必读

    Spring源码解析:Bean实例的创建与初始化 一. 什么是Ioc/DI? 二. Spring IOC体系结构 (1) BeanFactory (2) BeanDefinition 三. IoC容器 ...

  6. gdb调试用法

    目录 一.gdb功能简介 二.gdb使用前置条件:编译时加入debug信息. 三.gdb最常见的几个用法: 1.gdb的启动,加载程序: 2.调试正在运行的程序: 3. 查core: 四.gdb常用命 ...

  7. Exp5 MSF基础应用 20164320 王浩

    1. 实践目标 本实践目标是掌握metasploit的基本应用方式,重点常用的三种攻击方式的思路.具体需要完成: 1.1一个主动攻击实践,如ms08_067; (1分) 1.2 一个针对浏览器的攻击, ...

  8. SoupUI 5.1.2(专业版)下载(含破解文件)

    包内含原安装包和破解文件,仅用于技术交流,切勿用于商业用途. 安装教程参考:https://www.cnblogs.com/miaojjblog/p/9778839.html 安装包及破解文件下载地址 ...

  9. H3C设备系列问题

    一.h3c交换器和交换机的Telnet或SSH登录用户名和密码忘记了,怎么办? 处理步骤: 1.使用Console线连接交换机或路由器的Console口,确保笔记本已连上设备,在设备启动过程中根据提示 ...

  10. levmar : Levenberg-Marquardt库编译

    levmar : Levenberg-Marquardt 是非线性优化的一个库 1.使用CMake生成sln项目,编译 clapack库 在levmar工程中,打开misc.c文件,在最开始添加#in ...