sql 分页
SQL 分页
2023-06-13 09:12:01 时间
大家好,又见面了,我是你们的朋友全栈君。
//查询所有
public List<products>getAll(int pageNo,int count){
System.out.println(pageNo+";"+count);
System.out.println((pageNo-1)*count+1+";"+pageNo*count);
List<products> list=null;
String sql="select * from " +
"(select ROW_NUMBER()over(order by id) row,* from products where 0=0 ) t" +
" where row between "+((pageNo-1)*count+1)+" and "+pageNo*count;
System.out.println(sql);
try {
list=bs.getObjectList("com.web.Entity.products", sql);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
//获取总页数
//获取默认总页数
public int getPages(int count) {
int n=0;
String sql="select count(*) from products where 0=0";
n=bs.getPages(sql, count);
return n;
}
//条件查询
public List<products>getAll2(int pageNo,int count,QueryProduct qd){
List<products> list=null;
String sql="select * from " +
"(select ROW_NUMBER()over(order by id) row,* from products where 0=0";
String sql2=" ) t where row between "+((pageNo-1)*count+1)+" and "+pageNo*count;
if(qd.getPdName()!=null&&qd.getPdName()!="")
sql+=" and name like'%"+qd.getPdName()+"%'";
if(qd.getPdType()!=null&&qd.getPdType()!="")
sql+=" and typeCode like'%"+qd.getPdType()+"%'";
if(qd.isState()!=null&&qd.isState()!="")
if(!(qd.isState().equals("2")))
sql+=" and pdState="+qd.isState();
System.out.println(sql+sql2);
try {
list=bs.getObjectList("com.web.Entity.products", sql+sql2);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
//获取条件查询总页数
public int getPages2(int count,QueryProduct qd) {
int n=0;
String sql="select count(*) from products where 1=1";
if(qd.getPdName()!=null&&qd.getPdName()!="")
sql+=" and name like'%"+qd.getPdName()+"%'";
if(qd.getPdType()!=null&&qd.getPdType()!="")
sql+=" and typeCode like'%"+qd.getPdType()+"%'";
if(qd.isState()!=null&&qd.isState()!="") {
System.out.println(qd.isState());
System.out.println(qd.isState()=="2");
System.out.println(qd.isState().equals("2"));
if(!(qd.isState().equals("2")))
sql+=" and pdState="+qd.isState();
}
n=bs.getPages(sql, count);
return n;
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/155406.html原文链接:https://javaforall.cn
相关文章
- ORA-13841: SQL profile named string already exists for a different signature/category pair ORACLE 报错 故障修复 远程处理
- MySQL 建表SQL精选实例(mysql建表sql)
- Redis突破SQL:贴近一体化开发体验(redis支持sql)
- Oracle数据库表连接SQL技术指南(oracle表连接sql)
- Oracle 中优化SQL性能的终极指南(oracle中sql优化)
- 实现Oracle数据库分页查询的SQL示例(oracle分页sql)
- MySQL备份SQL:确保数据安全(mysql备份sql)
- 据库构建最佳的 MS SQL 小数据库系统(mssql小数)
- Oracle数据库抓取过程中的SQL技巧(oracle抓取sql)
- 大学生学习SQL Server编程的进阶之路(大学学sqlserver)
- SQL Server锁性能提升:释放新潜能(sqlserver锁升级)
- SQL Server卡慢:如何解决优化问题?(sqlserver 卡慢)
- 量SQL Server实现数据偏移量获取(sqlserver偏移)
- 新增:SQL Server:如何轻松实现新功能(sqlserver 今日)
- 如何利用Oracle掌握SQL写作技巧(oracle写sql格式)
- 使用SQL快速将数据导入Redis(sql导入redis)
- 优化 Oracle T SQL 性能的关键技巧(oracle t sql)
- 学习 Oracle SQL实战案例分享(oracle sql案例)
- 学习Oracle SQL数组的运用(oracle sql数组)
- Oracle Q转义解决SQL语句编写中的坎坷(oracle q 转义)
- 防SQL注入生成参数化的通用分页查询语句
- sql语句like多个条件的写法实例