博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
拼接json示例 json分页并显示所有页码
阅读量:5784 次
发布时间:2019-06-18

本文共 3290 字,大约阅读时间需要 10 分钟。

<%@ page language="java" import="java.util.*" pageEncoding="gbk"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>              jquery-ajax分页	
id name remark age hobby 操作

 

 

 

package com.jiang.action;import com.jiang.DB.GetData;import com.opensymphony.xwork2.ActionSupport;public class GetPageData extends ActionSupport {	private String p;//当前页	private String orderby;//排序规则	private String data;     public String getData() {		return data;	}	public void setData(String data) {		this.data = data;	}	public String getP() {		return p;	}	public void setP(String p) {		this.p = p;	}	public String getOrderby() {		return orderby;	}	public void setOrderby(String orderby) {		this.orderby = orderby;	}	public String execute()throws Exception{		System.out.println("p:"+p);		System.out.println("orderby:"+orderby);    	 if("".equals(orderby)){    		 orderby="order by id_t";    	 }    	 if("".equals(p)){    		 p=String.valueOf(1);    	 }    	 if(Integer.parseInt(p)==0){    		 p=String.valueOf(1);    	 }    	 data=GetData.getJson("pagetest", "*", "","order by id_t", Integer.parseInt(p), 3);    	 System.out.println("data:"+data);//    	 System.out.println(data);    	 return SUCCESS;     }}

 

打印结果:data:{"pageCount":"4","pageData":[{"id":"1","id_t":"1","name":"1","remark":"1","age":"1","hobby":"1"},{"id":"2","id_t":"2","name":"b","remark":"b","age":"b","hobby":"b"},{"id":"3","id_t":"3","name":"啊","remark":"啊","age":"啊","hobby":"啊"},{"id":"4","id_t":"4","name":"啊","remark":"啊","age":"啊","hobby":"啊"},]}

package com.jiang.DB;import java.sql.ResultSetMetaData;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import javax.sql.RowSet;public class GetData {     public static String getJson(String tableName,String select,String where,String orderby,int pageIndex,int pageCount){         StringBuilder sb=new StringBuilder();         sb.append("select "+select+" from "+tableName);         if(!"".equals(where)){        	 sb.append(" ");        	 if(where.startsWith("where")){        		 sb.append(" "+where);        	 }else{        		 sb.append(" where "+where);        	 }         }         sb.append(" "+orderby+" ");         int temp=(pageIndex-1)*pageCount;         sb.append(" limit "+temp+","+pageCount);    	 RowSet rt=DBop.search(sb.toString());    	 //求数据总条目数         int rowNum=0;         rowNum=DBop.getNum(tableName,where);    	 return RowSetToJson(rt,rowNum,pageCount);     }          /*      * @param count 数据总条目数      * @param pageCount 每页显示数据数      * */     private static String RowSetToJson(RowSet rt,int count,int pageCount){    	 ResultSetMetaData rm=null;    	 StringBuilder sb=new StringBuilder();    	 try {			 rm=rt.getMetaData();			 sb.append("{\"pageCount\":\""+count+"\",\"pageData\":[");			 int columNum=rm.getColumnCount();			 List
list=new ArrayList
(); for(int i=0;i

 源:http://a881127b.iteye.com/blog/972277

 

转载地址:http://jfvyx.baihongyu.com/

你可能感兴趣的文章
20180702搭建青岛RAC记录
查看>>
安装部署TIDB分布式数据库
查看>>
Spring Security OAuth 实现OAuth 2.0 授权
查看>>
linux文件及简单命令学习
查看>>
dubbo源码分析-架构
查看>>
新 Terraform 提供商: Oracle OCI, Brightbox, RightScale
查看>>
6套毕业设计PPT模板拯救你的毕业答辩
查看>>
IT兄弟连 JavaWeb教程 JSP与Servlet的联系
查看>>
Windows phone 8 学习笔记
查看>>
linux并发连接数:Linux下高并发socket最大连接数所受的各种限制
查看>>
详解区块链中EOS的作用。
查看>>
我的友情链接
查看>>
mysql-error 1236
查看>>
sshd_config设置参数笔记
查看>>
循序渐进Docker(一)docker简介、安装及docker image管理
查看>>
jsp页面修改后浏览器中不生效
查看>>
大恶人吉日嘎拉之走火入魔闭门造车之.NET疯狂架构经验分享系列之(四)高效的后台权限判断处理...
查看>>
Oracle HRMS,PeopleSoft HR,SAP HR区别
查看>>
信号量实现进程同步
查看>>
Spring4-自动装配Beans-通过构造函数参数的数据类型按属性自动装配Bean
查看>>