NutzCN Logo
问答 在easyui中用异步前台怎么接收参数啊
发布于 2322天前 作者 qq_30f823b4 1265 次浏览 复制 上一个帖子 下一个帖子
标签:

-------------------后台代码

@At("/dateGroupDay")
@Ok("json:full")
public Object dateGroupDay() {
// 创建客户对象集合

    List<CustomerManage> listCustomerManage = new ArrayList<CustomerManage>();
    System.out.println("111111111111");
    List<Object> list = null;
    try {

       //
       String path = MachineTableConfigAction.class.getResource("/conf.ini").getFile();
       File file = new File(path);
       String text = FileOPeration.readFile(file);
       String[] userName = text.split(";");
       if (userName.length > 1) {
         String userNameStr = userName[1].substring(userName[1].indexOf("=") + 1, userName[1].length());
         String nodeId = userName[0].substring(userName[0].indexOf("=") + 1, userName[0].length());
         String sqlstr = "select cm.id,user_name,user_pass,user_account,cm.node_id,priority,gatenum_id,database_id,login_url,"
              + "cm.app_id,cm.description,database_name,gatenum,gatenum_outside,sign_code "
              + "from node_manage nm,customer_manage cm,database_cust_manage dcm,gatenum_manage gm "
              + "where cm.node_id=nm.id and cm.database_id=dcm.id and cm.gatenum_id=gm.id and cm.node_id="
              + nodeId + "" + " and cm.user_name='" + userNameStr + "'";
         Sql sql = Sqls.create(sqlstr);
         sql.setCallback(Sqls.callback.entities());
         Entity<CustomerManage> entity = daoTest.getEntity(CustomerManage.class);
         sql.setEntity(entity);
         daoTest.execute(sql).getResult();
         listCustomerManage = sql.getList(CustomerManage.class);
       }
       System.err.println(listCustomerManage.size());
       // 判断用户是否存在
       if (listCustomerManage.size() > 0) {
         for (int i = 0; i < listCustomerManage.size(); i++) {
          String databaseName = listCustomerManage.get(i).getDatabaseName();
          String sqlSent = "SELECT COUNT( DATE_FORMAT( SENTTIME, '%Y-%m-%d' ) ) AS count,"
                 + "COUNT( CASE WHEN SMSSTATUS = 'DELIVRD' THEN 1 ELSE NULL END ) AS succeed,"
                 + "COUNT( CASE WHEN SMSSTATUS != 'DELIVRD' AND SMSSTATUS IS NOT NULL THEN 1 ELSE NULL END ) AS Failure,"
                 + "COUNT( CASE WHEN SMSSTATUS IS NULL THEN 1 ELSE NULL END ) AS wzh,"
                 + "DATE_FORMAT( SENTTIME, '%Y-%m-%d' ) AS time " + "FROM   " + databaseName
                 + " .SMS_SENT  WHERE DATE_FORMAT( NOW( ), '%Y-%m-%d' ) > DATE_FORMAT( SENTTIME, '%Y-%m-%d' ) "
                 + "GROUP BY  DATE_FORMAT( SENTTIME,'%Y-%m-%d' ) ORDER BY "
                 + "   DATE_FORMAT( SENTTIME, '%Y-%m-%d')   ";
          System.err.println("*-----------------------------" + sqlSent);
          Sql create = Sqls.create(sqlSent);

          create.setCallback(new SqlCallback() {
              @Override
              public ArrayList invoke(Connection con, ResultSet rs, Sql sql) throws SQLException {
                 ArrayList<Map> statistical = new ArrayList<>();
                 while (rs.next()) {
                   Map tempstatistical = new HashMap<>();
                   int count = rs.getInt("count");
                   int succeed = rs.getInt("succeed");
                   int Failure = rs.getInt("Failure");
                   int wzh = rs.getInt("wzh");
                   String time = rs.getString("time");
                   tempstatistical.put("count",count);
                   tempstatistical.put("succeed",succeed);
                   tempstatistical.put("Failure",Failure);
                   tempstatistical.put("wzh",wzh);
                   tempstatistical.put("time",time);
                   statistical.add(tempstatistical);

                 }

                 return statistical;
              }
          });

          list = daoTest.execute(create).getList(Object.class);

         }

       }

       System.err.println(list);
       return new NutMap().setv("unitList", list);
    } catch (Exception e) {
       e.printStackTrace();

       return null;
    }

}

-------------前台

var SteptypeGrid;
$(function() {
SteptypeGrid = $('#SteptypeGrid')
.datagrid(
{
url : '${pageContext.request.contextPath}/dateGroupAction/dateGroupDay.miao',
fitColumns : true,
border : false,
striped : true,
rownumbers : true,
pagination : true,
singleSelect : true,
idField : 'unitList',
columns : [ [ {
field : 'count',
title : '总数',
width : '300'
}, {
field : 'succeed',
title : '成功',
width : '100',
hidden : false
}, {
field : 'Failure',
title : '失败',
width : '200',

                 }, {
                   field : 'wzh',
                   title : '无回执',
                   width : '200',

                 }, {
                   field : 'time',
                   title : '日期',
                   width : '200',

                 } ] ]
              });
    alert(SteptypeGrid);

});




${obj.unitList }

开始日期 结束日期

<div data-options="region:'center',fit:true,border:false">
    <table id="SteptypeGrid"></table>
</div>

6 回复

有"插入代码"按钮!!!

<script type="text/javascript">

	var SteptypeGrid;
	$(function() {
		SteptypeGrid = $('#SteptypeGrid')
				.datagrid(
						{
							url : '${pageContext.request.contextPath}/dateGroupAction/dateGroupDay.miao',
							fitColumns : true,
							border : false,
							striped : true,
							rownumbers : true,
							pagination : true,
							singleSelect : true,
							idField : 'count',
							columns : [ [ {
								field : 'count',
								title : '总数',
								width : '300'
							}, {
								field : 'succeed',
								title : '成功',
								width : '100',
								hidden : false
							}, {
								field : 'Failure',
								title : '失败',
								width : '200',

							}, {
								field : 'wzh',
								title : '无回执',
								width : '200',

							}, {
								field : 'time',
								title : '日期',
								width : '200',

							} ] ]
						});
		alert(SteptypeGrid);

	});
</script>
</head>
<body >
	<h1>${obj.unitList }</h1>
	<form
		action="${pageContext.request.contextPath}/dateGroupAction/dateGroupDay.miao"
		method="post">
		开始日期 <input class="easyui-datetimebox" name="startTime"
			data-options="required:true,showSeconds:false" value="3/4/2018 2:3"
			style="width: 150px"> 结束日期 <input class="easyui-datetimebox"
			name="endTime" data-options="required:true,showSeconds:false"
			value="3/4/2018 2:3" style="width: 150px"> <input
			type="submit" value="查询">
	</form>

	<div data-options="region:'center',fit:true,border:false">
		<table id="SteptypeGrid"></table>
	</div>


</body>
</html>

@At("/dateGroupDay")
	@Ok("json:full")
	public Object dateGroupDay() {
		// 创建客户对象集合

		List<CustomerManage> listCustomerManage = new ArrayList<CustomerManage>();
		System.out.println("111111111111");
		List<Object> list = null;
		try {

			//
			String path = MachineTableConfigAction.class.getResource("/conf.ini").getFile();
			File file = new File(path);
			String text = FileOPeration.readFile(file);
			String[] userName = text.split(";");
			if (userName.length > 1) {
				String userNameStr = userName[1].substring(userName[1].indexOf("=") + 1, userName[1].length());
				String nodeId = userName[0].substring(userName[0].indexOf("=") + 1, userName[0].length());
				String sqlstr = "select cm.id,user_name,user_pass,user_account,cm.node_id,priority,gatenum_id,database_id,login_url,"
						+ "cm.app_id,cm.description,database_name,gatenum,gatenum_outside,sign_code "
						+ "from node_manage nm,customer_manage cm,database_cust_manage dcm,gatenum_manage gm "
						+ "where cm.node_id=nm.id and cm.database_id=dcm.id and cm.gatenum_id=gm.id and cm.node_id="
						+ nodeId + "" + " and cm.user_name='" + userNameStr + "'";
				Sql sql = Sqls.create(sqlstr);
				sql.setCallback(Sqls.callback.entities());
				Entity<CustomerManage> entity = daoTest.getEntity(CustomerManage.class);
				sql.setEntity(entity);
				daoTest.execute(sql).getResult();
				listCustomerManage = sql.getList(CustomerManage.class);
			}
			System.err.println(listCustomerManage.size());
			// 判断用户是否存在
			if (listCustomerManage.size() > 0) {
				for (int i = 0; i < listCustomerManage.size(); i++) {
					String databaseName = listCustomerManage.get(i).getDatabaseName();
					String sqlSent = "SELECT COUNT( DATE_FORMAT( SENTTIME, '%Y-%m-%d' ) ) AS count,"
							+ "COUNT( CASE WHEN SMSSTATUS = 'DELIVRD' THEN 1 ELSE NULL END ) AS succeed,"
							+ "COUNT( CASE WHEN SMSSTATUS != 'DELIVRD' AND SMSSTATUS IS NOT NULL THEN 1 ELSE NULL END ) AS Failure,"
							+ "COUNT( CASE WHEN SMSSTATUS IS NULL THEN 1 ELSE NULL END ) AS wzh,"
							+ "DATE_FORMAT( SENTTIME, '%Y-%m-%d' ) AS time " + "FROM   " + databaseName
							+ " .SMS_SENT  WHERE DATE_FORMAT( NOW( ), '%Y-%m-%d' ) > DATE_FORMAT( SENTTIME, '%Y-%m-%d' ) "
							+ "GROUP BY  DATE_FORMAT( SENTTIME,'%Y-%m-%d' ) ORDER BY "
							+ "   DATE_FORMAT( SENTTIME, '%Y-%m-%d')   ";
					System.err.println("*-----------------------------" + sqlSent);
					Sql create = Sqls.create(sqlSent);

					create.setCallback(new SqlCallback() {
						@Override
						public ArrayList invoke(Connection con, ResultSet rs, Sql sql) throws SQLException {
							ArrayList<Map> statistical = new ArrayList<>();
							while (rs.next()) {
								Map tempstatistical = new HashMap<>();
								int count = rs.getInt("count");
								int succeed = rs.getInt("succeed");
								int Failure = rs.getInt("Failure");
								int wzh = rs.getInt("wzh");
								String time = rs.getString("time");
								tempstatistical.put("count",count);
								tempstatistical.put("succeed",succeed);
								tempstatistical.put("Failure",Failure);
								tempstatistical.put("wzh",wzh);
								tempstatistical.put("time",time);
								statistical.add(tempstatistical);

							}

							return statistical;
						}
					});

					list = daoTest.execute(create).getList(Object.class);

				}

			}

			System.err.println(list);
			return new NutMap().setv("unitList", list);
		} catch (Exception e) {
			e.printStackTrace();

			return null;
		}

	}

在控制台调试jquery.easyui.min.js:9903 Uncaught TypeError: Cannot read property 'length' of undefined
at Object.render (jquery.easyui.min.js:9903)
at _5f6 (jquery.easyui.min.js:8837)
at jquery.easyui.min.js:9422
at Object.success (jquery.easyui.min.js:10128)
at j (jquery.min.js:2)
at Object.fireWith as resolveWith
at x (jquery.min.js:4)
at XMLHttpRequest.b (jquery.min.js:4)

得搞清楚他需要怎样结构的数据了

{
"unitList": [{
"wzh": 0,
"succeed": 2,
"count": 2,
"time": "2018-05-30",
"Failure": 0
}, {
"wzh": 2,
"succeed": 62,
"count": 101,
"time": "2018-08-11",
"Failure": 37
}, {
"wzh": 0,
"succeed": 7,
"count": 16,
"time": "2018-08-12",
"Failure": 9
}, {
"wzh": 21,
"succeed": 38,
"count": 69,
"time": "2018-08-13",
"Failure": 10
}]
}这是返回的数据

你确定easyui就是需要这样结构的数据?

添加回复
请先登陆
回到顶部