Hibernate分页

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

DAO类

package com.coolpep.order.dao;

import java.util.List;

public interface PaginationDAO {
 
 public int getCount(String cond) throws Exception;
 
 public int getPage(String cond) throws Exception;
 
 public List getPage(String cond, int page, int cont) throws Exception;

}

DAPImpl类

package com.coolpep.order.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.coolpep.order.dao.PaginationDAO;
import com.coolpep.order.factory.DAOFactory;

public class PaginationDAOImpl implements PaginationDAO {
 
 private Session session = null;
 private int totalPage;   //总页数
 private int totalCount;  //总行数
 private int pageSize = 5;   //页面显示条数
 private int currentPage; //当前页码

 public PaginationDAOImpl() {
  // TODO Auto-generated constructor stub
  this.session = new Configuration().configure().buildSessionFactory().openSession();
 }
 
 
 /**
  * 汇总数据获取数据总行数
  *
  * */
 public int getCount(String cond) throws Exception{
  int totalCount = 0;

  try {
   Transaction tran = this.session.beginTransaction();
   Query q = this.session.createQuery("select count(*) from Orders where osource=?");
   q.setString(0, cond);
   List list = q.list();
   totalCount = ((Integer) list.get(0)).intValue();
   tran.commit();
   this.session.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
  
  return totalCount;
 }
 
 /**
  * 汇总数据获取数据总页数
  *
  * */
 public int getPage(String cond) throws Exception{
  
  try{
   Transaction tran = this.session.beginTransaction();
   DAOFactory dao = new DAOFactory();
   totalCount = dao.getPaginationDAOInstance().getCount(cond);
   if(totalCount%pageSize>0)
    totalPage = totalCount/pageSize + 1;
   if(totalCount%pageSize==0)
    totalPage = totalCount/pageSize;
   if(totalCount%pageSize<0)
    totalPage = totalCount/pageSize;
   tran.commit();
   this.session.close();
  } catch (Exception e){
   e.printStackTrace();
  }
  return totalPage;
 }
 
 /**
  * 根据条件分页
  *
  * @param cond  查找条件
  * @param page  当前页数
  * @param count
  * */
 public List getPage(String cond, int currentPage, int pageSize){
  List list = null;
  String hql = "from Orders where osource=?";
  Query q = this.session.createQuery(hql);
  q.setString(0, cond);
  q.setFirstResult(pageSize*(currentPage-1));
  q.setMaxResults(pageSize);
  list = q.list();
  return list;
  
 }
 

}
 

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值