@Data public class ResponseBeanimplements Serializable { private static final long serialVersionUID = 3532176852796649340L; private T t; private String message; private Integer code; public static ResponseBean build(Integer code,String message,T t){ ResponseBean responseBean =new ResponseBean (); responseBean.setCode(code); responseBean.setMessage(message); responseBean.setT(t); return responseBean; } public static ResponseBean success(){ ResponseBean responseBean=build(SysConstants.SUCCESS,SysConstants.SUCCESS_MSG,null); return responseBean; } public static ResponseBean success(T t){ ResponseBean responseBean=build(SysConstants.SUCCESS,SysConstants.SUCCESS_MSG,t); return responseBean; } public static ResponseBean success(String message,T t){ ResponseBean responseBean=build(SysConstants.SUCCESS,message,t); return responseBean; } public static ResponseBean error(){ ResponseBean responseBean=build(SysConstants.ERROR,SysConstants.ERROR_MSG,null); return responseBean; } public static ResponseBean error(String message){ ResponseBean responseBean=build(SysConstants.ERROR,message,null); return responseBean; } public static ResponseBean error(Integer code,String message){ ResponseBean responseBean=build(code,message,null); return responseBean; } }
**
* @描述
* @创建人 admin
* @创建时间 2022/6/1 14:44
**/
public class SysConstants {
public static final Integer SUCCESS = 200;
public static final Integer REFUSE = 202;
public static final Integer ERROR = 500;
public static final String SUCCESS_MSG = "请求成功";
public static final String ERROR_MSG = "请求失败";
}
使用:
private static ResponseBean getUser() {
List list= new ArrayList();
User user =new User();
user.setAge(1);
user.setId("1");
user.setName("sahs");
User user2 =new User();
user2.setAge(2);
user2.setId("2");
user2.setName("s233");
list.add(user);
list.add(user2);
Map map =new HashMap();
map.put("1","sss");
return ResponseBean.success(list);
}


