电商网站项目(一)用户模块---门户
2023-09-11 14:18:56 时间
1、作为后台的开发人员我们需要根据接口来封装一些后台的一些相应方法,高可用的服务端相应类:
这里我们来总结下:
/** * 服务端的返回响应对象 */ //当程序返回结果失败的时候,此时data是null,这个时候我们不需要返回data的null,利用这个NON_NULL,我们就不返回空的data @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) public class ServerResponse<T> implements Serializable { private int status; private String msg; private T data; private ServerResponse(int status) { this.status = status; } private ServerResponse(int status, T data) { this.status = status; this.data = data; } //这里需要注意的是,如果将private改为public时,是传递给T data呢还是传递给String msg呢,这是需要注意的 private ServerResponse(int status, String msg) { this.status = status; this.msg = msg; } private ServerResponse(int status, String msg, T data) { this.status = status; this.msg = msg; this.data = data; } @JsonIgnore public boolean isSuccess(){ return this.status==ResponseCode.SUCCESS.getCode(); } public int getStatus() { return status; } public String getMsg() { return msg; } public T getData() { return data; } public static <T> ServerResponse<T> createBySuccess(){ return new ServerResponse<T>(ResponseCode.SUCCESS.getCode()); } public static <T> ServerResponse<T> createBySuccessMessage(String msg){ return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(),msg); } public static <T> ServerResponse<T> createBySuccess(T data){ return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(),data); } public static <T> ServerResponse<T> createBySuccess(String msg,T data){ return new ServerResponse<T>(ResponseCode.SUCCESS.getCode(),msg,data); } public static <T> ServerResponse<T> createByError(){ return new ServerResponse<T>(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc()); } public static <T> ServerResponse<T> createByErrorMessage(String errorMessage){ return new ServerResponse<T>(ResponseCode.ERROR.getCode(),errorMessage); } public static <T> ServerResponse<T> createByErrorCodeMessage(int errorCode,String errorMessage){ return new ServerResponse<T>(errorCode,errorMessage); } }
2、枚举类型的定义:
/** * 定义返回类型的code数据表示 */ public enum ResponseCode { //枚举类:系统为这两个对象默认的加上了public static final SUCCESS(0,"SUCCESS"), ERROR(1,"ERROR"), NEED_LOGIN(10,"NEED_LOGIN"), ILLEGAL_ARGUMENT(2,"ILLEGAL_ARGUMENT"); // 1.枚举类对象的属性不应允许被改动,所以应该使用private final 修饰 private final int code; private final String desc; // 2.枚举类的使用private final 修饰的属性因该在构造器中为其赋值 ResponseCode(int code, String desc) { this.code = code; this.desc = desc; } //供外界调用开放入口 public int getCode() { return code; } public String getDesc() { return desc; } }
相关文章
- 一个Android项目多线程下载模块开源库:AndroidFileDownloader
- Apicloud_(项目)网上书城03_拓展模块实现
- eclipse上搭建maven多模块Java Web项目
- 【华为云实战开发】1.传统Java项目怎么能变得高大上?
- DOTS项目设置
- android开发学习---基础知识学习、如何导入已有项目和开发一个电话拨号器
- 8-crm项目-kingadmin,列表页---搜索
- 路飞学城项目-登陆认证模块
- python-django框架-电商项目-商品模块开发_20191124
- python-django框架-电商项目-用户模块开发_20191117
- Intent Flag实际项目 -- 超时跳转登录界面并清理前面所有activity
- 28款GitHub最流行的开源机器学习项目
- go项目多阶段构建Dockerfile脚本示例
- 如何在React项目中使用ECharts图表库
- SAP Spartacus 项目里的 ng-package.json
- 【项目实战】自定义设置Sonar的规则,要求DevOps工具链SonarQube只扫描指定模块
- 〖Python 数据库开发实战 - Python与MySQL交互篇⑫〗- 项目实战- 实现新闻管理模块
- NuxtJS项目——开发工具
- 求教:在SpringBoot框架下基于MAVEN的多模块项目,怎么进行DAO层的单元测试?
- centos安装python3/pip3项目所需的第三方模块(在线安装&&离线安装)
- Android性能优化实战解析(腾讯、字节、阿里、百度、网易...)互联网公司项目实战+案例分析
- 【项目实战】常见的开源软件协议优缺点对比
- 【最全最详细】Jenkins+Docker 一键自动化部署 SpringBoot 项目
- idea创建多模块Springboot项目、导入多模块、删除多模块
- 【PART 2】OAK-D+TurtleBot3机器人项目全解析
- chat集群聊天室项目 代码+讲解(二):业务模块
- chat集群聊天室项目 代码+讲解(一):网络模块
- Nginx内存池源码移植项目