首页 > Web开发 > 详细

jsonArray返回

时间:2019-02-27 16:12:39      阅读:137      评论:0      收藏:0      [点我收藏+]

dao

 <select id="selectShopInfo"  resultType="java.util.HashMap">
 SELECT  *   FROM shop_info  si  
<if test="datadate != null and datadate != ‘‘ ">  
         WHERE 
        DATE_FORMAT(#{datadate},%Y-%m-%d)=DATE_FORMAT(ctime,%Y-%m-%d)
   </if>
      </select> 
  
  
  
    <select id="selectCustomerInfo" resultType="java.util.HashMap">
     SELECT  *   FROM customer_info   ci 
    <if test="datadate != null and datadate != ‘‘ ">  
         WHERE 
        DATE_FORMAT(#{datadate},%Y-%m-%d)=DATE_FORMAT(ctime,%Y-%m-%d)
   </if>
  </select> 

 

dao

//获取门店信息
    public   List<HashMap<String, Object>> selectShopInfo(@Param("datadate")String datadate) throws Exception;
    
    //获取客户信息 
    public List<HashMap<String,Object>> selectCustomerInfo(@Param("datadate")String datadate) throws Exception;
     

 

service.impl

@Override
    public JSONObject selectInfo(String datadate) throws Exception {
        JSONObject object=new JSONObject();
         List<HashMap<String, Object>> shopInfo =interfaceDao.selectShopInfo(datadate);
         List<HashMap<String, Object>> customerInfo =interfaceDao.selectCustomerInfo(datadate);
            JSONArray shopArray=new JSONArray();
         for (int i = 0; i < shopInfo.size(); i++) {
             HashMap<String, Object> map=shopInfo.get(i);
             JSONObject shopObj=new JSONObject();
             Set set = map.keySet();
             Iterator iter = set.iterator();
             while (iter.hasNext()) {
             String key = (String) iter.next();
             
             if(  map.get(key)==null ) {
                 shopObj.accumulate(key,"");
             }else {
                 shopObj.accumulate(key,map.get(key).toString().equals("")?"":map.get(key).toString());
             }
        
             }
             shopArray.add(shopObj);
        }
         
         
         JSONArray customerArray=new JSONArray();
         for (int i = 0; i < customerInfo.size(); i++) {
             HashMap<String, Object> map=customerInfo.get(i);
             JSONObject customerObj=new JSONObject();
             Set set = map.keySet();
             Iterator iter = set.iterator();
             while (iter.hasNext()) {
             String key = (String) iter.next();
             
             if( map.get(key)==null ) {
                 customerObj.accumulate(key,"");
             }else {
                 customerObj.accumulate(key, map.get(key).toString().equals("")?"":map.get(key).toString());
             }
            
             }
             customerArray.add(customerObj);
        }
            object.accumulate("shopInfo", shopArray);
            object.accumulate("customerInfo", customerArray);
 
        return object;
    }

 

action

    public  void  getBasicInfo () {
        response.setHeader("Content-type", "application/json;charset=UTF-8");
        response.setCharacterEncoding("UTF-8");
        JSONObject object=new JSONObject();
        String datadate=request.getParameter("datadate");
        try {
            object =interfaceService.selectInfo(datadate);
            object.accumulate("status",200);
        } catch (Exception e) {
            object.accumulate("error", e.getMessage());
            object.accumulate("status",500);
            e.printStackTrace();
        }
        WebPageUtil.writeBack(object.toString());
    }

 

jsonArray返回

原文:https://www.cnblogs.com/Yusco/p/10444341.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!