package dao;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import java.util.*;
import entity.*;
public class BookManage extends HibernateDaoSupport {
// 添加新的图书
public int addBook(Book book) {
int i = 0;
try {
this.getHibernateTemplate().save(book);//利用hibernate的模板操作,编码简单
i = 1;
} catch (Exception e) {
e.printStackTrace();
}
return i;
}
// 修改图书
public int updateBook(Book book) {
int i = 0;
try {
this.getHibernateTemplate().update(book);
i = 1;
} catch (Exception e) {
e.printStackTrace();
}
return i;
}
// 根据图书ID查询该图书
public Book findBook(int bookId) {
try {
Book book = (Book) this.getHibernateTemplate().get("entity.Book",bookId);
return book;
} catch (RuntimeException re) {
throw re;
}
}
// 查询销量最好的图书
@SuppressWarnings("unchecked")
public List<Book> bestSellingBook(int pageNumber, int pageSize) {
String hql = "from Book as book where book.bookSales > 0 and book.bookAmount > 0 order by book.bookSales desc ";
try {
List<Book> bestSellingBook = this.getHibernateTemplate().find(hql);
return bestSellingBook;
} catch (RuntimeException re) {
throw re;
}
}
// 查询最新上架的图书
@SuppressWarnings("unchecked")
public List<Book> latestBook(int pageNumber, int pageSize) {
String hql = "from Book as book where book.bookAmount > 0 order by book.bookShelveTime desc ";
try {
List<Book> latestBook = this.getHibernateTemplate().find(hql);
return latestBook;
} catch (RuntimeException re) {
throw re;
}
}
// 查询推荐图书ID
@SuppressWarnings("unchecked")
public List<Recommended> allRecommended(int pageNumber, int pageSize) {
String hql = "from Recommended as recommended ";
try {
List<Recommended> allRecommended = this.getHibernateTemplate().find(hql);
return allRecommended;
} catch (RuntimeException re) {
throw re;
}
}
// 查询特价图书ID
@SuppressWarnings("unchecked")
public List<Bargain> allBargain(int pageNumber, int pageSize) {
String hql = "from Bargain as bargain ";
try {
List<Bargain> allBargain = this.getHibernateTemplate().find(hql);
return allBargain;
} catch (RuntimeException re) {
throw re;
}
}
// 根据图书名称查询图书
@SuppressWarnings("unchecked")
public List<Book> allBookByName(String bookName, int pageNumber,
int pageSize) {
String hql = "from Book as book where book.bookName like '%" + bookName + "%'";
try {
this.getHibernateTemplate().setMaxResults(pageSize);
List<Book> allBookByName = this.getHibernateTemplate().find(hql);
return allBookByName;
} catch (RuntimeException re) {
throw re;
}
}
// 根据作者查询图书
@SuppressWarnings("unchecked")
public List<Book> allBookByAuthor(String bookAuthor, int pageNumber, int pageSize) {
String hql = "from Book as book where book.bookAuthor like '%" + bookAuthor + "%'";
try {
this.getHibernateTemplate().setMaxResults(pageSize);
List<Book> allBookByAuthor = this.getHibernateTemplate().find(hql);
return allBookByAuthor;
} catch (RuntimeException re) {
throw re;
}
}
// 根据出版社查询图书
@SuppressWarnings("unchecked")
public List<Book> allBookByPress(String bookPress, int pageNumber, int pageSize) {
String hql = "from Book as book where book.bookPress like '%" + bookPress + "%'";
try {
this.getHibernateTemplate().setMaxResults(pageSize);
List<Book> allBookByPress = this.getHibernateTemplate().find(hql);
return allBookByPress;
} catch (RuntimeException re) {
throw re;
}
}
//根据类别ID来获取类别
public Type findType(int typeId){
try{
Type type = (Type)this.getHibernateTemplate().get("entity.Type", typeId);
return type;
}catch(RuntimeException re){
throw re;
}
}
//根据图书类别来查询图书
@SuppressWarnings("unchecked")
public List<Book> allBookByType(int typeId, int pageNumber, int pageSize){
String hql = "from Book as book where book.type.typeId="+typeId;
try{
List<Book> allBookByType= this.getHibernateTemplate().find(hql);
return allBookByType;
}catch(RuntimeException re){
throw re;
}
}
//查询图书是否为特价图书
@SuppressWarnings("unchecked")
public Bargain isBargain(int bookId){
Bargain bargain = null;
String hql = "from Bargain as bargain where bargain.book.bookId="+bookId;
try{
List<Bargain> bargainList = this.getHibernateTemplate().find(hql);
if(bargainList.size() > 0){
bargain = bargainList.get(0);
}
}catch(RuntimeException re){
throw re;
}
return bargain;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
网上书店-SSH源码初版 (238个子文件)
applicationContext.xml.bak 5KB
struts.xml.bak 4KB
struts.xml.bak 4KB
UpdateBookAction.class 6KB
BookAction.class 5KB
BookManage.class 5KB
OrdersManage.class 4KB
Book.class 4KB
UserManageAction.class 4KB
OrdersManageAction.class 4KB
ShoppingCartAction.class 3KB
OneTypeAction.class 3KB
PersonManage.class 3KB
UpdateCartAction.class 3KB
User.class 3KB
SingleOrdersAction.class 3KB
EnrollAction.class 3KB
LoginAction.class 2KB
OrdersAction.class 2KB
Orders.class 2KB
AllBookAction.class 2KB
AllOrdersAction.class 2KB
OrdersManage$2.class 2KB
DealOrdersAction.class 2KB
ManagerLoginCheck.class 2KB
SingleBookAction.class 2KB
ManagerLoginCheck.class 2KB
Ordersbook.class 1KB
OrdersManage$1.class 1KB
UserInformationAction.class 1KB
UserExitAction.class 1KB
Bargain.class 1KB
Manager.class 1KB
LeftAction.class 1KB
UserLoginCheck.class 1KB
Recommended.class 903B
Type.class 888B
Sex.class 879B
.classpath 8KB
org.eclipse.wst.common.component 553B
org.eclipse.wst.jsdt.ui.superType.container 49B
styles.css 3KB
style.css 3KB
Thumbs.db 31KB
logo.gif 5KB
body.gif 3KB
bottom.html 574B
error.html 551B
bottom.html 424B
struts2-core-2.0.14.jar 2.22MB
hibernate3.jar 2.15MB
jasperreports-2.0.5.jar 1.87MB
aspectjweaver.jar 1.82MB
jgroups-2.2.8.jar 1.54MB
iText-2.0.7.jar 1.15MB
poi-3.0.1.jar 888KB
freemarker.jar 843KB
freemarker-2.3.8.jar 784KB
jxl.jar 704KB
mysql.jar 687KB
c3p0-0.9.1.2.jar 596KB
c3p0-0.9.1.jar 594KB
jboss-jmx.jar 578KB
jboss-common.jar 570KB
commons-collections.jar 546KB
struts.jar 537KB
jboss-cache.jar 505KB
spring-beans.jar 473KB
proxool-0.8.3.jar 465KB
javassist.jar 460KB
spring-context.jar 458KB
xwork-2.0.7.jar 449KB
antlr-2.7.6.jar 433KB
jboss-archive-browsing.jar 404KB
spring-webmvc.jar 393KB
velocity-1.5.jar 383KB
log4j-1.2.15.jar 383KB
spring-orm.jar 364KB
log4j-1.2.11.jar 342KB
spring-aop.jar 318KB
cglib-nodep-2.1_3.jar 317KB
spring-jdbc.jar 310KB
dom4j-1.6.1.jar 307KB
commons-httpclient.jar 298KB
spring-core.jar 279KB
cglib-2.1.3.jar 276KB
hibernate-annotations.jar 259KB
commons-lang.jar 237KB
spring-tx.jar 222KB
jaxen-1.1-beta-7.jar 222KB
jboss-system.jar 218KB
ehcache-1.2.3.jar 203KB
spring-web.jar 183KB
concurrent-1.3.2.jar 167KB
ognl-2.6.11.jar 164KB
spring-webmvc-portlet.jar 146KB
jotm.jar 121KB
commons-dbcp.jar 119KB
hibernate-entitymanager.jar 114KB
velocity-tools-view-1.4.jar 113KB
共 238 条
- 1
- 2
- 3
资源评论
- yerg11212018-01-25没有数据库 代码有问题啊
- 帅欢2017-12-23你没数据库啊
- DanielYuan_9112017-09-30给杀毒软件给删了
kingszelda
- 粉丝: 54
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 预警插件-Fine-report11
- 基于JavaWeb的汽车租赁平台论文.doc
- 基于web的在线学习管理系统设计与实现
- C语言结构体精讲,结构体在内存中的访问
- ip地址查询区域代码包括php c++ python golang java rust代码使用例子
- 视图库级联抓包,支持GA/T1400-2018版,包括Register, keepalive, subscribe, subscribeNotification等
- 尚硅谷宋红康C语言精讲.zip
- (175909636)全国293个地级市的经纬度信息
- (174549194)ANSYS Fluent Tutorial Guide
- (15341010)经典C程序一百例
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功