公用返回类用泛型,返回固定格式

公用返回类用泛型,返回固定格式

不在需要用继承的方式一个baseresponse 一个子类(继承baseresponse) 这样,直接公用返回类用泛型传入这个子类

应用:

  @ResponseBody

    @RequestMapping(value = { "/saveUserRole" }, method = RequestMethod.POST,produces="application/json;charset=UTF-8")

    public BaseResponse<String>  saveUserRole(@RequestBody(required = true) FinancialSalesUserRole financialSalesUserRole){

        BaseResponse<String> baseResponse =new BaseResponse<String>();

        try{

            financialSalesUserFacade.saveUserRole(financialSalesUserRole);

//         financialSalesUserFacade.deleteUserRole(financialSalesUserRole.getUserId());

//         financialSalesUserFacade.insertUserRole(financialSalesUserRole);

            baseResponse.setData("1");

        }catch (Exception e){

        }

        return baseResponse;

    }

     @ResponseBody

    @RequestMapping(value = { "/list" }, method = RequestMethod.GET,produces="application/json;charset=UTF-8")

    @ApiResponses(value = {@ApiResponse(code = 200, message = "商品信息",  response=String.class),

            @ApiResponse(code = 201, message = "q"+ "(token验证失败)",  response=String.class),

            @ApiResponse(code = 202, message = "500" + "(系统错误)",response = String.class)})

    @ApiOperation(value="查询列表",notes="/list",response = String.class)

    public BaseResponse<List<FinancialSalesUser>> getweixinBaseInfoList() {

        String q="";

        BaseResponse<List<FinancialSalesUser>> baseResponse =new  BaseResponse<List<FinancialSalesUser>>();

        try {

//            CoreBusinessType condition = new CoreBusinessType();

//            condition.setTypeName("车抵贷");

            FinancialSalesUserCondition financialSalesUserCondition =new FinancialSalesUserCondition();

             List<FinancialSalesUser> list= financialSalesUserFacade.selectAll(financialSalesUserCondition);

            baseResponse.setData(list);

            if (baseResponse != null && CollectionUtils.isNotEmpty(baseResponse.getData())) {

               q= JSON.json(baseResponse.getData());

                log.info(JSON.json(baseResponse.getData()));

//                modelMap.put("coreTypeList", baseResponse.getData());

            }

        } catch (Exception e) {

           log.error("错误"+e);

        }

       

        return baseResponse;

    }

//

// Source code recreated from a .class file by IntelliJ IDEA

// (powered by Fernflower decompiler)

//

package com.houbank.basic.util.response;

import java.io.Serializable;

public class BaseResponse<T> implements Serializable {

    private static final long serialVersionUID = 6298151416887583602L;

    protected boolean success = true;

    protected String errorCode;

    protected String message;

    protected T data;

    public BaseResponse() {

    }

    public BaseResponse(T t) {

        this.data = t;

    }

    public BaseResponse(String errorCode, String returnMessage) {

        this.success = false;

        this.errorCode = errorCode;

        this.message = returnMessage;

    }

    public BaseResponse(boolean success, String returnMessage) {

        this.success = false;

        this.message = returnMessage;

    }

    public boolean isSuccess() {

        return this.success;

    }

    public String getErrorCode() {

        return this.errorCode;

    }

    public String getMessage() {

        return this.message;

    }

    public T getData() {

        return this.data;

    }

    public void setSuccess(boolean success) {

        this.success = success;

    }

    public void setErrorCode(String errorCode) {

        this.errorCode = errorCode;

    }

    public void setMessage(String message) {

        this.message = message;

    }

    public void setData(T data) {

        this.data = data;

    }

    public boolean equals(Object o) {

        if(o == this) {

            return true;

        } else if(!(o instanceof BaseResponse)) {

            return false;

        } else {

            BaseResponse other = (BaseResponse)o;

            if(!other.canEqual(this)) {

                return false;

            } else if(this.isSuccess() != other.isSuccess()) {

                return false;

            } else {

                label49: {

                    String this$errorCode = this.getErrorCode();

                    String other$errorCode = other.getErrorCode();

                    if(this$errorCode == null) {

                        if(other$errorCode == null) {

                            break label49;

                        }

                    } else if(this$errorCode.equals(other$errorCode)) {

                        break label49;

                    }

                    return false;

                }

                String this$message = this.getMessage();

                String other$message = other.getMessage();

                if(this$message == null) {

                    if(other$message != null) {

                        return false;

                    }

                } else if(!this$message.equals(other$message)) {

                    return false;

                }

                Object this$data = this.getData();

                Object other$data = other.getData();

                if(this$data == null) {

                    if(other$data != null) {

                        return false;

                    }

                } else if(!this$data.equals(other$data)) {

                    return false;

                }

                return true;

            }

        }

    }

    protected boolean canEqual(Object other) {

        return other instanceof BaseResponse;

    }

    public int hashCode() {

        boolean PRIME = true;

        byte result = 1;

        int result1 = result * 59 + (this.isSuccess()?79:97);

        String $errorCode = this.getErrorCode();

        result1 = result1 * 59 + ($errorCode == null?43:$errorCode.hashCode());

        String $message = this.getMessage();

        result1 = result1 * 59 + ($message == null?43:$message.hashCode());

        Object $data = this.getData();

        result1 = result1 * 59 + ($data == null?43:$data.hashCode());

        return result1;

    }

    public String toString() {

        return "BaseResponse(success=" + this.isSuccess() + ", errorCode=" + this.getErrorCode() + ", message=" + this.getMessage() + ", data=" + this.getData() + ")";

    }

}

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2404194