| | |
| | | package com.hx.resultTool; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.hx.exception.TipsException; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 统一返回格式 |
| | |
| | | |
| | | /**校验返回码*/ |
| | | public Boolean checkCode(){ |
| | | if(!ResponseCode.SUCCESS.equals(code)){ |
| | | return false; |
| | | if(ResponseCode.SUCCESS.equals(code)){ |
| | | return true; |
| | | } |
| | | return true; |
| | | return false; |
| | | } |
| | | |
| | | /**校验返回码,进行错误提示*/ |
| | | public void checkTips(){ |
| | | if(!ResponseCode.SUCCESS.equals(code)){ |
| | | throw new TipsException("请求失败:"+this.code+","+this.msg); |
| | | } |
| | | } |
| | | |
| | | /**返回数据转JSONObject*/ |
| | | public JSONObject getJsonObject(Object data){ |
| | | return JSONObject.parseObject(JSON.toJSONString(data)); |
| | | } |
| | | |
| | | /**返回数据转JSONArray*/ |
| | | public JSONArray getJsonArray(Object data){ |
| | | return JSONArray.parseArray(JSON.toJSONString(data)); |
| | | } |
| | | |
| | | /**返回数据转对象*/ |
| | | public <T> T getObject(Object data, Class<T> clazz) { |
| | | return JSONObject.parseObject(JSON.toJSONString(data), clazz); |
| | | } |
| | | |
| | | /**返回数据转列表*/ |
| | | public <T> List<T> getArray(Object data, Class<T> clazz) { |
| | | return JSONArray.parseArray(JSON.toJSONString(data), clazz); |
| | | } |
| | | |
| | | /*******************************************************************************/ |