package com.yjd.nb.dao.impl;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.yjd.domain.common.PageModel;
import com.yjd.nb.common.HibernateUtils;
import com.yjd.nb.dao.MessageDao;
import com.yjd.nb.domain.Message;
/**
* 留言Dao接口的实现类
*/
public class MessageDaoImpl implements MessageDao {
/* (non-Javadoc)
* @see com.tjitcast.nb.dao.MessageDao#add(com.tjitcast.nb.domain.Message)
*/
public void add(Message msg) {
Session session = null;
Transaction tx = null;
try {
session = HibernateUtils.getSession();
tx = session.beginTransaction();
session.save(msg);
tx.commit();
} catch (Exception e) {
if(tx != null){
tx.rollback();
}
e.printStackTrace();
}finally{
if(session != null){
session.close();
}
}
}
/* (non-Javadoc)
* @see com.tjitcast.nb.dao.MessageDao#countAll()
*/
public int countAll() {
int count = 0;
Session session = null;
Transaction tx = null;
try {
session = HibernateUtils.getSession();
tx = session.beginTransaction();
Long temp = (Long)session.createQuery("select count(*) from Message").uniqueResult();
if(temp != null && temp.intValue() > 0){
count = temp.intValue();
}
tx.commit();
} catch (Exception e) {
if(tx != null){
tx.rollback();
}
e.printStackTrace();
}finally{
if(session != null){
session.close();
}
}
return count;
}
/* (non-Javadoc)
* @see com.tjitcast.nb.dao.MessageDao#findByPage(int, int)
*/
@SuppressWarnings("unchecked")
public PageModel<Message> findByPage(int pageNo, int pageSize) {
PageModel<Message> pm = new PageModel<Message>();
pm.setPageNo(pageNo);
pm.setPageSize(pageSize);
int recordCount = this.countAll();
if(recordCount > 0){
pm.setRecordCount(recordCount);
List<Message> list = new ArrayList<Message>();
Session session = null;
Transaction tx = null;
try {
session = HibernateUtils.getSession();
tx = session.beginTransaction();
list = session.createQuery("from Message order by id desc")
.setFirstResult((pageNo - 1) * pageSize)
.setMaxResults(pageSize)
.list();
tx.commit();
pm.setData(list);
} catch (Exception e) {
if(tx != null){
tx.rollback();
}
e.printStackTrace();
}finally{
if(session != null){
session.close();
}
}
}
return pm;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Struts2+Hibernate框架,非常简单的组合,专门提供给菜鸟级别的
共87个文件
jar:24个
gif:23个
java:9个
需积分: 9 6 下载量 84 浏览量
2010-12-30
18:44:54
上传
评论
收藏 10.68MB RAR 举报
温馨提示
这个Struts2和Hibernate的组合,非常简单,简单明了教你如何分层,如何……
资源推荐
资源详情
资源评论
收起资源包目录
s2h-model.rar (87个子文件)
s2h-model
.project 1KB
test
com
yjd
nb
service
MessageServiceTest.java 2KB
.settings
.jsdtscope 500B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 300B
WebRoot
login.jsp 1KB
WEB-INF
web.xml 657B
lib
javassist-3.7.ga.jar 531KB
junit-4.7.jar 227KB
c3p0-0.9.1.jar 594KB
mysql-connector-java-5.1.12-bin.jar 716KB
jta-1.1.jar 11KB
javassist-3.12.0.GA.jar 618KB
hibernate3.jar 3.9MB
jstl.jar 20KB
slf4j-log4j12-1.6.1.jar 10KB
xwork-core-2.2.1.jar 997KB
freemarker-2.3.16.jar 860KB
struts2-core-2.2.1.jar 755KB
commons-collections-3.1.jar 546KB
commons-fileupload-1.2.1.jar 56KB
hibernate-jpa-2.0-api-1.0.0.Final.jar 99KB
log4j-1.2.16.jar 470KB
dom4j-1.6.1.jar 307KB
mypager-1.0-GA.jar 4KB
ognl-3.0.jar 224KB
slf4j-api-1.6.1.jar 25KB
jakarta-oro.jar 64KB
antlr-2.7.6.jar 433KB
commons-io-1.3.2.jar 86KB
standard.jar 384KB
classes
log4j.properties 2KB
com
yjd
domain
common
PageModel.class 2KB
nb
dao
impl
MessageDaoImpl.class 3KB
MessageDao.class 338B
domain
Message.hbm.xml 669B
Message.class 3KB
web
action
IndexAction.class 2KB
MsgAction.class 1KB
common
HibernateUtils.class 866B
service
MessageServiceTest.class 3KB
MessageService.class 977B
struts.xml 954B
hibernate.cfg.xml 1KB
index.jsp 173B
META-INF
MANIFEST.MF 36B
main.jsp 4KB
images
15.gif 4KB
1.gif 3KB
email.gif 637B
titlebg.jpg 10KB
8.gif 4KB
16.gif 5KB
18.gif 4KB
19.gif 5KB
12.gif 5KB
20.gif 3KB
11.gif 3KB
10.gif 5KB
7.gif 4KB
17.gif 4KB
4.gif 4KB
3.gif 4KB
13.gif 3KB
5.gif 4KB
2.gif 4KB
6.gif 4KB
14.gif 5KB
8_online.gif 1KB
style.css 285B
9.gif 5KB
ip.gif 1KB
manage
list.jsp 1KB
.myeclipse
src
com
yjd
domain
common
PageModel.java 1KB
nb
dao
MessageDao.java 718B
impl
MessageDaoImpl.java 3KB
domain
Message.hbm.xml 669B
Message.java 2KB
web
action
IndexAction.java 1KB
MsgAction.java 864B
common
HibernateUtils.java 600B
service
MessageService.java 548B
config
log4j.properties 2KB
struts.xml 954B
hibernate.cfg.xml 1KB
.classpath 2KB
共 87 条
- 1
资源评论
Java高知社区
- 粉丝: 1926
- 资源: 90
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功