類中的每一個方法都是幹什麼的?(注:用My Eclipse ,還有事struts1)
package stu.dao;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import stu.common.PageResult;
import stu.common.Util;
import stu.entity.Books;
/**
* A data access object (DAO) providing persistence and search support for Books
* entities. Transaction control of the save(), update() and delete() operations
* can directly support Spring container-managed transactions or they can be
* augmented to handle user-managed Spring transactions. Each of these methods
* provides additional information for how to configure it for the desired type
* of transaction control.
*
* @see stu.entity.Books
* @author MyEclipse Persistence Tools
*/
public class BooksDAO extends BaseDAO {
private static final Log log = LogFactory.getLog(BooksDAO.class);
// property constants
public static final String BTITLE = "btitle";
public static final String CID = "cid";
public static final String BPUBLISH = "bpublish";
public static final String BATHORS = "bathors";
public static final String BSUM = "bsum";
public static final String BQUANTITY = "bquantity";
public static final String BDETALIS = "bdetalis";
protected void initDao() {
// do nothing
}
public void save(Books transientInstance) {
log.debug("saving Books instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Books persistentInstance) {
log.debug("deleting Books instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Books findById(java.lang.Integer id) {
log.debug("getting Books instance with id: " + id);
try {
Books instance = (Books) getHibernateTemplate().get(
"stu.entity.Books", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Books instance) {
log.debug("finding Books instance by example");
try {
List results = getHibernateTemplate().findByExample(instance);
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Books instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Books as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByBtitle(Object btitle) {
return findByProperty(BTITLE, btitle);
}
public List findByCid(Object cid) {
return findByProperty(CID, cid);
}
public List findByBpublish(Object bpublish) {
return findByProperty(BPUBLISH, bpublish);
}
public List findByBathors(Object bathors) {
return findByProperty(BATHORS, bathors);
}
public List findByBsum(Object bsum) {
return findByProperty(BSUM, bsum);
}
public List findByBquantity(Object bquantity) {
return findByProperty(BQUANTITY, bquantity);
}
public List findByBdetalis(Object bdetalis) {
return findByProperty(BDETALIS, bdetalis);
}
public List findAll() {
log.debug("finding all Books instances");
try {
String queryString = "from Books";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Books merge(Books detachedInstance) {
log.debug("merging Books instance");
try {
Books result = (Books) getHibernateTemplate().merge(
detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Books instance) {
log.debug("attaching dirty Books instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Books instance) {
log.debug("attaching clean Books instance");
try {
getHibernateTemplate().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static BooksDAO getFromApplicationContext(ApplicationContext ctx) {
return (BooksDAO) ctx.getBean("BooksDAO");
}
public void list(Books books, PageResult pageResult) {
// TODO Auto-generated method stub
String hql = "from Books d where 1=1 ";
if (null!=books)
{
if (Util.isNotNullOrEmpty(books.getBtitle()))// 標題
{
hql += "and d.btitle like '%" + books.getBtitle() + "%' ";
}
if (Util.isNotNullOrEmpty(books.getBathors()))//作者
{
hql += "and d.bauthor like '%" + books.getBathors() + "%' ";
}
/*if (books.getCid()!= null)//類別
{
hql += "and d.type.cid = " + books.get
}
*/
}
super.list(hql, pageResult);
}
}
--------------------------------------------------------------------------------------------------------------------
實體類
package stu.entity;
import java.util.HashSet;
import java.util.Set;
/**
* Books entity. @author MyEclipse Persistence Tools
*/
public class Books implements java.io.Serializable {
// Fields
private Integer bid;
private String btitle;
private Integer cid;
private String bpublish;
private String bathors;
private Integer bsum;
private Integer bquantity;
private String bdetalis;
private Set lrbooks = new HashSet(0);
// Constructors
/** default constructor */
public Books() {
}
/** full constructor */
public Books(String btitle, Integer cid, String bpublish, String bathors,
Integer bsum, Integer bquantity, String bdetalis, Set lrbooks) {
this.btitle = btitle;
this.cid = cid;
this.bpublish = bpublish;
this.bathors = bathors;
this.bsum = bsum;
this.bquantity = bquantity;
this.bdetalis = bdetalis;
this.lrbooks = lrbooks;
}
// Property accessors
public Integer getBid() {
return this.bid;
}
public void setBid(Integer bid) {
this.bid = bid;
}
public String getBtitle() {
return this.btitle;
}
public void setBtitle(String btitle) {
this.btitle = btitle;
}
public Integer getCid() {
return this.cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getBpublish() {
return this.bpublish;
}
public void setBpublish(String bpublish) {
this.bpublish = bpublish;
}
public String getBathors() {
return this.bathors;
}
public void setBathors(String bathors) {
this.bathors = bathors;
}
public Integer getBsum() {
return this.bsum;
}
public void setBsum(Integer bsum) {
this.bsum = bsum;
}
public Integer getBquantity() {
return this.bquantity;
}
public void setBquantity(Integer bquantity) {
this.bquantity = bquantity;
}
public String getBdetalis() {
return this.bdetalis;
}
public void setBdetalis(String bdetalis) {
this.bdetalis = bdetalis;
}
public Set getLrbooks() {
return this.lrbooks;
}
public void setLrbooks(Set lrbooks) {
this.lrbooks = lrbooks;
}
}