• spring mvc 利用匿名内部类构建返回json对象


        @RequestMapping(value = "/order/findOrderByIdVague/{noId}.json", method = {RequestMethod.GET,RequestMethod.POST})
        public  @ResponseBody List findOrderByIdVague(@PathVariable String noId){
            ApiModel model=null;
            if (noId==null || noId.length()<6.){
                model=new ApiModel("订单模糊查询只支持6个以上的字符",201);
                return null;
            }
            List list= orderService.findOrderByIdVague(noId);
           List<Object> resultList=new ArrayList<Object>(list.size());
    
           for (final Object orderObject:list){
               if (orderObject instanceof  Object[]){
                   final Object[] orderStringObj= (Object[]) orderObject;
                   if (orderStringObj==null || orderStringObj.length!=5)
                       continue;;
                   Object object=new Object(){
                       private String value=(orderStringObj[0]==null?"":orderStringObj[0].toString());
                       private String masterNickname=(orderStringObj[1]==null?"":orderStringObj[1].toString());
                       private String masterMobile=(orderStringObj[2]==null?"":orderStringObj[2].toString());
                       private String memberNickname=(orderStringObj[3]==null?"":orderStringObj[3].toString());
                       private String memberMobile=(orderStringObj[4]==null?"":orderStringObj[4].toString());
    
                       public String getValue(){
                           return value;
                       }
                       public String getMasterNickname() {
                           return masterNickname;
                       }
                       public String getMasterMobile() {
                           return masterMobile;
                       }
                       public String getMemberNickname() {
                           return memberNickname;
                       }
                       public String getMemberMobile() {
                           return memberMobile;
                       }
                   };
                   resultList.add(object);
               }
           }
            return  resultList;
        }
    

      

    内部类的代码:
     Object object=new Object(){……}

  • 相关阅读:
    PHP之PHPExcel X
    Docker之基础(一) X
    Django Admin之常用功能汇总 X
    pycharm中配置启动Django项目 X
    银联支付接入新一代 X
    pycharm集成Jupyter Notebook X
    Django之model外键 X
    Django之添加prometheus监控 X
    Yii2 中配置方法汇总 X
    python常用模块汇总 X
  • 原文地址:https://www.cnblogs.com/jifeng/p/4474137.html
Copyright © 2020-2023  润新知