接口返回格式
作者:互联网
返回json
{
"message": "success!",
"resultCode": 1,
"data": {
"IMdate": {
"data": {
"resultCode": "1"
},
"userInfo": {
"user": {
"id": 80,
"telephone": "13873540969",
"password": "710a1acc761d9d698836171767f417d5",
"areaCode": 86,
"yuumiId": "YM-17186275",
"nickName": null,
"sex": null,
"explain": null,
"email": null,
"picUrl": null,
"imUid": 10000408,
"deviceToken": "1322",
"pwd": "834557",
"isLogined": 1
},
"userAccount": {
"id": 39,
"yuumiUserId": 80,
"balance": "2.00|0.1350",
"precharge": null
},
"version": {
"id": 1,
"version": "v1",
"download": "1234",
"versionInfo": "324",
"type": 1,
"publish": "2020-11-03T06:00:00.000+00:00",
"versionCode": 1
}
}
}
}
controller
@Override
public ResponseProtocol<Map<String,Object>> login(String telephone,String areaCode ,String passwrod,String grantType) {
YuumiUser retUser =findByTelephone(telephone);
System.out.println("telephone="+telephone);
System.out.println("retUser="+retUser);
ResponseProtocol<Map<String,Object>> resp = new ResponseProtocol<Map<String,Object>>();
Map<String, Object> map = new LinkedHashMap<>();
// IMResultVO vo = IMLogin(telephone,retUser.getPwd());
//账户信息
YuumiUserAccount account = this.yuumiUserAccountService.findByYuumiUserId(retUser.getId());
//版本信息
Version version = this.versionService.find();
//费率信息
List<AreaFee> af = this.areaFeeService.findByAreaCode2(retUser.getAreaCode());
resp.setMessage(Constant.SUCCESS);
UserVO uv = new UserVO();
uv.setVersion(version);
uv.setAreaFee(af);
uv.setUser(retUser);
uv.setUserAccount(account);
// map.put("IMdate",vo);
map.put("userInfo",uv);
resp.setData(map);
resp.setResultCode(Constant.RET_CODE_SUCCESS);
return resp;
}
第一层
package com.duolian.callyuumi.util;
/**
* @Author markLu
* @Date: 2020/10/3115:32
*/
public class ResponseProtocol<T> {
/***
* 响应信息,无论成功还是失败,都需要写入相应的信息
*/
private String message;
/**
* 0失败 1成功
*/
private Integer resultCode;
/***
* 响应数据
*/
private T data;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Integer getResultCode() {
return resultCode;
}
public void setResultCode(Integer resultCode) {
this.resultCode = resultCode;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
package com.duolian.callyuumi.util;
import com.duolian.callyuumi.entity.AreaFee;
import com.duolian.callyuumi.entity.Version;
import com.duolian.callyuumi.entity.YuumiUser;
import com.duolian.callyuumi.entity.YuumiUserAccount;
import java.util.List;
/**
* @Author markLu
* @Date: 2020/10/2816:09
*/
public class UserVO<T>{
private YuumiUser user;
private YuumiUserAccount userAccount;
private List<AreaFee> areaFee;
private Version version;
public YuumiUserAccount getUserAccount() {
return userAccount;
}
public void setUserAccount(YuumiUserAccount userAccount) {
this.userAccount = userAccount;
}
public List<AreaFee> getAreaFee() {
return areaFee;
}
public void setAreaFee(List<AreaFee> areaFee) {
this.areaFee = areaFee;
}
public YuumiUser getUser() {
return user;
}
public void setUser(YuumiUser user) {
this.user = user;
}
public Version getVersion() {
return version;
}
public void setVersion(Version version) {
this.version = version;
}
}
package com.duolian.callyuumi.util;
/**
* @Author markLu
* @Date: 2020/10/2816:09
*/
public class IMResultVO<T> {
private Object data;
private String resultCode;
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public String getResultCode() {
return resultCode;
}
public void setResultCode(String resultCode) {
this.resultCode = resultCode;
}
}
标签:返回,return,String,void,接口,格式,resultCode,data,public 来源: https://blog.csdn.net/qq_42981242/article/details/110881433