博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
拼接json示例 json分页并显示所有页码
阅读量:5785 次
发布时间: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/

你可能感兴趣的文章
nagios一键安装脚本,nagios监控被监控主机上的应用服务mysql数据库
查看>>
grep 命令
查看>>
JS二维数组的声明和使用
查看>>
v$archive_gap dg dataguard 断档处理 scn恢复
查看>>
问责IT风险管理:CIO需关注两个重点
查看>>
Winform打包发布图解
查看>>
PDF文件怎么编辑,超简单的方法
查看>>
EasyUI基础入门之Easyloader(载入器)
查看>>
Uva 839 Not so Mobile
查看>>
30款超酷的HTTP 404页面未找到错误设计
查看>>
程序猿必备 MyEclipse2013-2014系列
查看>>
java中ArrayList 、LinkList区别
查看>>
Spring ’14 Wave Update: Installing Dynamics CRM on Tablets for Windows 8.1
查看>>
利用rand7()构造rand10()
查看>>
MySQL 备份与恢复
查看>>
吃午饭前,按书上的代码写会儿--Hunt the Wumpus第一个版本
查看>>
easyui中combobox的值改变onchang事件
查看>>
Eclipse魔法堂:任务管理器
查看>>
一周自学动态站点设计
查看>>
poj万人题
查看>>