• Controller返回结果处理


    1.创建一个返回结果的类

    package com.**.common.constants;
    
    import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
    
    /**
     * 异步请求统一返回结果集
     * @author 
     * 2017年1月24日 下午3:22:39
     */
    @JsonIgnoreProperties(value = { "hibernateLazyInitializer",
            "javassistLazyInitializer" })
    public class ApiResult {
    
        /** 成功还是失败 */
        private boolean success = true;
        /** 返回code */
        private String code = "";
        /** 返回的信息 */
        private String message = "";
        /** 返回的数据 */
        private Object data;
        
        
    
        public Object getData() {
            return data;
        }
    
        public void setData(Object data) {
            this.data = data;
        }
    
        public ApiResult() {
            super();
        }
    
        public ApiResult(boolean success) {
            super();
            this.success = success;
        }
    
        public ApiResult(String code, String message) {
            super();
            this.code = code;
            this.message = message;
            this.success = false;
        }
    
        public boolean isSuccess() {
            return success;
        }
    
        public void setSuccess(boolean success) {
            this.success = success;
        }
    
        public String getCode() {
            return code;
        }
    
        public void setCode(String code) {
            this.code = code;
        }
    
        public String getMessage() {
            return message;
        }
    
        public void setMessage(String message) {
            this.message = message;
        }
    
        public ApiResult(boolean success, String code, String message) {
            super();
            this.success = success;
            this.code = code;
            this.message = message;
        }
    
        public ApiResult(String message) {
            super();
            this.message = message;
        }
    
        public ApiResult(boolean success, String message) {
            super();
            this.success = success;
            this.message = message;
        }
        
        public ApiResult(boolean success, String code, String message,Object data) {
            super();
            this.success = success;
            this.code = code;
            this.message = message;
            this.data=data;
        }    
        
        public ApiResult(String code, String message,Object data) {
            super();
            this.code = code;
            this.message = message;
            this.data=data;
        }    
        
        public ApiResult(Object data) {
            super();
            this.data=data;
        }    
    }

    例:

    @RequestMapping("/getApponitmentData")
        public ApiResult getApponitmentData(HttpServletRequest request){
            Long shopid = AuthUtils.getCacheUser(request).getShopId(); 
            SMerchantInfo merchantInfo = sMerchantInfoService.findById(shopid);
            Map<String,Object>  resultdata = Maps.newHashMap();
            Integer  openSubscribeAudit = merchantInfo.getOpenSubscribeAudit();
            resultdata.put("openSubscribeAudit",openSubscribeAudit );
            if (openSubscribeAudit == NumberUtils.INTEGER_ZERO){
                List<SubscribeListmanageVo> vos = this.subscribeListService.getAppointmentByMerchant(shopid);
                resultdata.put("dataVos", vos);
            }
            
            return new ApiResult(resultdata);
        }
  • 相关阅读:
    Java实现 蓝桥杯VIP 算法训练 拦截导弹
    Java实现 蓝桥杯VIP 算法训练 拦截导弹
    Java实现 蓝桥杯VIP 算法训练 回文数
    Java实现 蓝桥杯VIP 算法训练 回文数
    Java实现 蓝桥杯VIP 算法训练 集合运算
    好看的游戏soul calibur
    程序员的出路(要非常专一门技术才行,超过80%的同行,或者积累自己的类库和产品)
    Qt的版本历史
    红魔城传说:血色交响曲 (2009)(东方系列游戏,实在是太美了)
    QString和char字符数组之间的转换(QTextCodec.toUnicode方法,特别注意的问题)
  • 原文地址:https://www.cnblogs.com/-scl/p/7382113.html
Copyright © 2020-2023  润新知