HIbernate+struts2分页案例
[html]<pre name="code" class="html">package www.csdn.project.util;
import org.hibernate.Session;
/**
* Data access inte易做图ce for domain model
* @author MyEclipse Persistence Tools
*/
public inte易做图ce IBaseHibernateDAO {
public Session getSession();
}</pre><br>
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><hibernate-configuration><session-factory><property name="myeclipse.connection.profile">localhost</property><property
name="connection.url">jdbc:mysql://localhost:3306/bookstore</property><property name="connection.username">root</property><property name="connection.password">root</property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property
name="dialect">org.hibernate.dialect.MySQLDialect</property><property name="show_sql">true</property><mapping resource="www/csdn/project/domain/Admin.hbm.xml" /></session-factory></hibernate-configuration>
<pre></pre>
<p><br>
</p>
<p><br>
</p>
<p></p>
<pre name="code" class="java">package www.csdn.project.dao;
import www.csdn.project.domain.Admin;
public inte易做图ce AdminDAO extends BaseDAO<Admin, Integer> {
}</pre><br>
<pre name="code" class="java">package www.csdn.project.dao;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Query;
import www.csdn.project.domain.Admin;
import www.csdn.project.util.BaseHibernateDAO;
import www.csdn.project.util.HiberSessionFactory;
public class AdminDAOImpl extends BaseHibernateDAO implements AdminDAO {
public Integer getCountRecord() {
int i = 0;
try {
Query query = this.getSession().createQuery(
"select count(admin) from Admin admin");
/*
* Long l = (Long) query.uniqueResult(); int i =
* Integer.parseInt(l.toString());
*/
i = Integer.parseInt(query.uniqueResult().toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
HiberSessionFactory.closeSession();
}
return i;
}
public List<Admin> getNowPageInfo(Integer nowpage) {
List<Admin> entities = new ArrayList<Admin>();
try {
entities = this.getSession().createQuery("from Admin")
.setFirstResult((nowpage - 1) * PAGESIZE).setMaxResults(
PAGESIZE).list();
} catch (Exception e) {
e.printStackTrace();
} finally {
HiberSessionFactory.closeSession();
}
return entities;
}
/*public Integer getCountRecord(Class className){
int i=0;
try {
i = this.getSession().createCriteria(className).list().size();
} catch (Exception e) {
e.printStackTrace();
} finally {
HiberSessionFactory.closeSession();
}
return 0;
}*/
public Integer getCountRecord(Class<Admin> className) {
int i = 0;
try {
Query query = this.getSession().createQuery(
"select count(c) from "+className.getName()+" c");
/*
* Long l = (Long) query.uniqueResult(); int i =
* Integer.parseInt(l.toString());
*/
i = Integer.parseInt(query.uniqueResult().toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
HiberSessionFactory.closeSession();
}
return i;
}
&nb
补充:Web开发 , Jsp ,
- 更多JS疑问解答:
- 几个验证11位手机号码格式的js代码
- js把图片转换成 base64代码
- js把base代码转换成图片
- JS 将 base64编码的图片转化为图片文件
- js中的定时器
- js如何获得FCKeditor控件的值
- 用js限制投票的cookie .目前设置的为:<input type="" class="" onclick="'window.location...
- JS验证,这块“牛皮”反复修改都不能实现
- 在JS中使用DOM模型
- 如何用JS 获取本地文件夹的文件列表
- js中new 了两个Object数组。怎么样将数组内容合并,重复的内容?
- 求实现自动生成图片缩略图的JS代码
- JS脚本网页问题
- js,代码中"object"和"Object"区别?
- js+flash实现网页图片切换效果,出现边框,单击激活此控件。