返回值DataResponse

来源:互联网 发布:pptv网络电视 编辑:程序博客网 时间:2024/05/29 15:55

1、BaseResponse

public class BaseResponse{  protected boolean success = false;  protected String msg;  public boolean isSuccess()  {    return this.success;  }  public void setSuccess(boolean success) {    this.success = success;  }  public String getMsg() {    return this.msg;  }  public void setMsg(String msg) {    this.msg = msg;  }}

 2、AddResponse

public class AddResponse extends BaseResponse{  private Object data;  public Object getData()  {    return this.data;  }  public void setData(Object data) {    this.data = data;  }}

 

3、DataResponse

public class DataResponse extends BaseResponse{  private Map<String, Object> data = new HashMap();  public Map<String, Object> getData() {    return this.data;  }  public void setData(Map<String, Object> data) {    this.data = data;  }}

 

例子:

@RequestMapping(value = "/getLimitDetails", method = {RequestMethod.GET,RequestMethod.POST})@ResponseBodypublic DataResponse getLimitDetails(Long id,Long parentId) {DataResponse response = new DataResponse();SmIaasQuotaV result = null;try {result = limitService.getLimitDetails(id,parentId);if(result != null){response.setData(BeanMapper.map(result, Map.class));response.setSuccess(true);}} catch(BusinessException e) {throw new ControllerException(HttpStatus.OK, e.getCode(), e.getMessage());} catch(Exception e) {final String msg = messageSource.getMessage(TipsConstants.QUERY_FAILURE);throw errorLogService.throwControllerException(LOGGER, HttpStatus.OK, null, msg, msg+",getLimitDetails error", e);}return response;}

 前台:

$.ajax({         url: _root + "/limit/getLimitDetails?id="+node.id+"&parentId="+node.parentId,         type: "GET",          dataType: "json",         async:false,         success: function (data, textStatus, XMLHttpRequest) {          if(data.success){        var model = data.data;               $("#instanceLimits").val(model.instanceLimits);      $("#publicIpLimits").val(model.publicIpLimits);。。。          }                  }     });

 

。。

 

 

 

 

 

 

0 0
原创粉丝点击