一、使用统一返回对象
大部分前后端项目采用 JSON 格式进行数据交互,定义一个统一的数据规范,有利于前后台的交互、以及信息处理。比如如下:
【输出格式如下所示】
{"success": true,"code": 200,"message": "查询用户列表","data": {"itms": [{"id": "1","username": "admin","role": "ADMIN","createTime": "2020-4-24T15:32:29","modifiedTime": "2020-4-24T15:41:40"},{"id": "2","username": "zhangsan","role": "USER","createTime": "2020-4-24T15:32:29","modifiedTime": "2020-4-24T15:41:40"}]}
}
经典代码结构如下:
package com.baomidou.springboot.entity.exception;import lombok.Data;
import org.apache.http.Ht