📄 goodsdao.java
字号:
package com.oa.db;
import java.util.List;
import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class GoodsDao extends HibernateDaoSupport {
/**
* 查询所以的物品购买记录
*
* @return list
*/
public List findAll() {
List list = null;
try {
list = (List) this.getHibernateTemplate().find("from Goods");
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
/**
* 添加新的物品记录
*
* @param goods
*/
public void addGoods(Goods goods) {
try {
this.getHibernateTemplate().save(goods);
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 根据物品记录id查询购买记录
*
* @param id
* @return list
*/
public List findById(int id) {
List list = null;
try {
list = (List) this.getHibernateTemplate().find("from Goods where id=?", id);
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
/**
* 根据物品名称模糊查询购买物品记录
* @param goodsName
* @return
*/
public List findByGoodsName(String goodsName) {
List list = null;
try {
list = (List) this.getHibernateTemplate().find("from Goods where goodsname like ?", "%"+goodsName+"%");
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
/**
* 更名物品购买记录
*
* @param goods
*/
public void updateGoods(Goods goods) {
try {
this.getHibernateTemplate().update(goods);
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 根据id删除物品购买记录
*
* @param id
*/
public void deleteGoods(int id) {
List list = null;
try {
list = (List) this.getHibernateTemplate().find("from Goods where id=?", id);
if (list != null && list.size() != 0) {
Goods goods = (Goods) list.get(0);
this.getHibernateTemplate().delete(goods);
}
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -