jsonArray返回
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返回的更多相关文章
- 自己写ORM框架 DBUtils_DG Java(C#的写在链接里)
ORM框架想必大家都比较熟知了,即对象关系映射(英语:Object Relation Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不同 ...
- MyEclipse下Struts2配置使用和Ajax、JSON的配合
原创文章,转载请注明:MyEclipse下Struts2配置使用和Ajax.JSON的配合 By Lucio.Yang 新手,初学Struts2的配置,同时尝试与Ajax通过JSON交互.首先介绍M ...
- jQuery+Ajax+Jsp做二级级联
终于弄懂了这个级联,我去!必须得在博客记下来. 1, JS代码: $(document).ready(function(){ $("#select1").change(functi ...
- java之接口文档规范
一.xxxxxx获取指定任务爬取的所有url的接口 接口名称:xxxxxx获取指定任务爬取的所有url的接口 访问链接: http://IP:PORT/crwalTask/findUrlExcepti ...
- [JSONObject/JSONArray] - 定制的JSON格式返回
当前开发的程序中.因为抛弃了jsp的渲染,改为thymeleaf,并在比较厉害的前端进行数据json的渲染无误后,得出此json数据返回. 以往的Map<String,Object>返回j ...
- JSONArray ja = JSONArray.fromObject(list);//特殊类 用于将list转化为JSON 数据并返回 out.print(ja);
JSONArray ja = JSONArray.fromObject(list);//特殊类 用于将list转化为JSON 数据并返回out.print(ja);
- Java中使用JSONTokener判断接口返回字符串是JSONObject还是JSONArray
今天在接口对接中,遇到一个问题,对方接口返回的JSONString,类型不确定,所以需要先做判断再进行处理.查阅资料后使用JSONTokener可进行处理,特此记录. String ret = ord ...
- 返回值List是JsonArray
MyController中: index.jsp中
- ajax提交数据到java后台,并且返回json格式数据前台接收处理值
1.前台html页面.有一段代码如下: 账 户: <input type="text" name="userName" id="userN& ...
随机推荐
- ubuntu下安装php7
apt-cache pkgnames | grep php7.0 sudo apt-get install -y php7.0 libapache2-mod-php7.0 php7.0-cli php ...
- jQuery-1.样式篇---选择器
jQuery选择器之id选择器 页面的任何操作都需要节点的支撑,开发者如何快速高效的找到指定的节点也是前端开发中的一个重点.jQuery提供了一系列的选择器帮助开发者达到这一目的,让开发者可以更少的处 ...
- 【Java】字符串工具类
import android.annotation.SuppressLint; import java.io.UnsupportedEncodingException; import java.uti ...
- 软件工程 week 02
一.地址链接 1.作业地址:https://edu.cnblogs.com/campus/nenu/2016CS/homework/2110 2.git仓库地址:https://git.coding. ...
- day05 字典
今日内容(dict) 1.基本格式 2.独有方法 3.公共 4.强制转换 1.基本格式 字典(可变类型,3.6之后是有序) 帮助用户去表示一个事物的信息(事物是有多个属性) 键值不能为集合,列表,字典 ...
- 加载XML文件到系统中
using System;using System.Data;using System.IO;using System.Xml;using System.Collections.Generic; na ...
- C-Language Functions
转自:https://www.postgresql.org/docs/9.6/xfunc-c.html 可以作为学习基于c编写pg extension 的资料 36.9. C-Language Fun ...
- go 调用windows dll 的方法
go 调用windows dll 的方法 ,代码如下: package main import ( "fmt" "syscall" "time&quo ...
- phpStudy2018 在win7下切换php7不成功解决办法
phpstudy 由2016升级到2018后,在切换版本时,php5.6及以下版本可以正常切换,切换7.0以上的版本时访问页面报 0xc000007b 错误,网上找了很多方法都没能解决,最后发现是没装 ...
- 请确保 ASP.NET State Service (ASP.NET 状态服务)已启动 问题解决
当iis部署的网站访问遇到如下错误时: 无法向会话状态服务器发出会话状态请求.请确保 ASP.NET State Service (ASP.NET 状态服务)已启动,并且客户端端口与服务器端口相同.如 ...