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 = ; 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 = ; 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",);
} catch (Exception e) {
object.accumulate("error", e.getMessage());
object.accumulate("status",);
e.printStackTrace();
}
WebPageUtil.writeBack(object.toString());
}

jsp

{"shopInfo":[],"customerInfo":[],"status":200}

jsonArray返回的更多相关文章

  1. 自己写ORM框架 DBUtils_DG Java(C#的写在链接里)

    ORM框架想必大家都比较熟知了,即对象关系映射(英语:Object Relation Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不同 ...

  2. MyEclipse下Struts2配置使用和Ajax、JSON的配合

    原创文章,转载请注明:MyEclipse下Struts2配置使用和Ajax.JSON的配合  By Lucio.Yang 新手,初学Struts2的配置,同时尝试与Ajax通过JSON交互.首先介绍M ...

  3. jQuery+Ajax+Jsp做二级级联

    终于弄懂了这个级联,我去!必须得在博客记下来. 1, JS代码: $(document).ready(function(){ $("#select1").change(functi ...

  4. java之接口文档规范

    一.xxxxxx获取指定任务爬取的所有url的接口 接口名称:xxxxxx获取指定任务爬取的所有url的接口 访问链接: http://IP:PORT/crwalTask/findUrlExcepti ...

  5. [JSONObject/JSONArray] - 定制的JSON格式返回

    当前开发的程序中.因为抛弃了jsp的渲染,改为thymeleaf,并在比较厉害的前端进行数据json的渲染无误后,得出此json数据返回. 以往的Map<String,Object>返回j ...

  6. JSONArray ja = JSONArray.fromObject(list);//特殊类 用于将list转化为JSON 数据并返回 out.print(ja);

    JSONArray ja = JSONArray.fromObject(list);//特殊类 用于将list转化为JSON 数据并返回out.print(ja);

  7. Java中使用JSONTokener判断接口返回字符串是JSONObject还是JSONArray

    今天在接口对接中,遇到一个问题,对方接口返回的JSONString,类型不确定,所以需要先做判断再进行处理.查阅资料后使用JSONTokener可进行处理,特此记录. String ret = ord ...

  8. 返回值List是JsonArray

    MyController中: index.jsp中

  9. ajax提交数据到java后台,并且返回json格式数据前台接收处理值

    1.前台html页面.有一段代码如下: 账  户:  <input type="text" name="userName" id="userN& ...

随机推荐

  1. noj二分查找

    二分查找: 要么左边,要么右边,哈哈哈哈 描述 给定一个单调递增的整数序列,问某个整数是否在序列中.   输入 第一行为一个整数n,表示序列中整数的个数:第二行为n(n不超过10000)个整数:第三行 ...

  2. 2017-9-3模拟赛T2 取数(win)

    题目 题解 做法1: 直接暴力枚举每个数是否被选出,计算平均数-中位数,并与当前答案进行比较.复杂度O(2^n),能过60%的数据. 做法2: 将每个数排序后枚举中位数. 首先,取奇数个数一定更优.容 ...

  3. 剑指Offer 10. 矩形覆盖 (递归)

    题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 题目地址 https://www.nowcoder.com/ ...

  4. Restful levels &HATEOAS基本介绍~

    本文所涉及的内容摘自:http://www.manongjc.com/article/93934.html 什么是RESTful REST这个词,是Roy Thomas Fielding在他2000年 ...

  5. 记一次ssh配置的锅

    我们在使用git来管理代码的时候不可避免的要用到ssh密匙,这个密匙怎么配置的百度上很多. 我这边是使用sourcetree来配合管理代码的,但是我ssh配置好了以后无论是克隆代码还是推送代码都提示我 ...

  6. Redis之在Linux上安装和简单的使用

    我只是一个搬运工 Redis之在Linux上安装和简单的使用https://blog.csdn.net/qq_20989105/article/details/76390367 一.安装gcc 1.R ...

  7. [ Codeforces Round #549 (Div. 2)][D. The Beatles][exgcd]

    https://codeforces.com/contest/1143/problem/D D. The Beatles time limit per test 1 second memory lim ...

  8. #考研笔记#计算机之PPT问题

    PPT1. 幻灯片母版.版式.模板之间的联系与区别?见下 12 2. 占位符的意义用于幻灯片上,就表现为一个虚框,虚框内部往往有“单击此处添加标题”之类的提示语,一旦鼠标点击之后,提示语会自动消失.当 ...

  9. java——慎用可变参数列表

    说起可变参数,我们先看下面代码段,对它有个直观的认识,下方的红字明确地解释了可变参数的意思: public class VarargsDemo{ static int sum(int... args) ...

  10. golang-generate-1pixel-image

    package main import ( "bytes" "encoding/base64" "flag" "html/temp ...