帮我解释下这段代码
publicclassTAdminDAOextendsHibernateDaoSupport{privatestaticfinalLoglog=LogFactory.ge...
public class TAdminDAO extends HibernateDaoSupport {
private static final Log log = LogFactory.getLog(TAdminDAO.class);
// property constants
public static final String USER_NAME = "userName";
public static final String USER_PW = "userPw";
protected void initDao() {
// do nothing
}
public void save(TAdmin transientInstance) {
log.debug("saving TAdmin instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(TAdmin persistentInstance) {
log.debug("deleting TAdmin instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public TAdmin findById(java.lang.Integer id) {
log.debug("getting TAdmin instance with id: " + id);
try {
TAdmin instance = (TAdmin) getHibernateTemplate().get(
"com.model.TAdmin", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
}
public List findByExample(TAdmin instance) {
log.debug("finding TAdmin 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 TAdmin instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from TAdmin as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
} 展开
private static final Log log = LogFactory.getLog(TAdminDAO.class);
// property constants
public static final String USER_NAME = "userName";
public static final String USER_PW = "userPw";
protected void initDao() {
// do nothing
}
public void save(TAdmin transientInstance) {
log.debug("saving TAdmin instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(TAdmin persistentInstance) {
log.debug("deleting TAdmin instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public TAdmin findById(java.lang.Integer id) {
log.debug("getting TAdmin instance with id: " + id);
try {
TAdmin instance = (TAdmin) getHibernateTemplate().get(
"com.model.TAdmin", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
}
public List findByExample(TAdmin instance) {
log.debug("finding TAdmin 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 TAdmin instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from TAdmin as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
} 展开
1个回答
展开全部
这段代码其实就是三个方法 一个保存,一个删除, 还有一个按ID查找,首先的话先声明两个变量 姓名和 密码
第一个保存方法 调用Hibernate 中的getHibernateTemplate().sava()方法 在括号中传入需要保存的参数,然后检测这段代码,如果成功显示save successful 失败的话抛出异常save failed
以此类推一下方法都是通过Hibernate 的 getHibernateTemplate()中的方法来实现的
第一个保存方法 调用Hibernate 中的getHibernateTemplate().sava()方法 在括号中传入需要保存的参数,然后检测这段代码,如果成功显示save successful 失败的话抛出异常save failed
以此类推一下方法都是通过Hibernate 的 getHibernateTemplate()中的方法来实现的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询