return (Organization)getHibernateTemplate().load(Organization.class, orgId);
package com.bjsxt.oa.manager.impl;import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.bjsxt.oa.manager.OrgManager;
import com.bjsxt.oa.model.Organization;
public class OrgManagerImpl extends HibernateDaoSupport implements OrgManager {
public void addOrg(Organization org, int parentId) {
if(parentId != 0){
org.setParent(findOrg(parentId));
}
getHibernateTemplate().save(org);
//自动生成机构编号
org.setSn(
(org.getParent() == null ? "" : org.getParent().getSn() + "_")
+ org.getId()
);
getHibernateTemplate().update(org);
}
public void delOrg(int orgId) {
Organization org = findOrg(orgId);
//判断子机构列表是否为空
if(org.getChildren().size() > 0){
throw new RuntimeException("存在子机构信息,不允许删除");
}
//判断人员是否非空
String hql = "select count(*) from Person p where p.org.id = ?";
Long personSize = (Long)getSession().createQuery(hql).setParameter(0, orgId).uniqueResult();
if(personSize > 0){
throw new RuntimeException("机构下面有人员信息,不允许删除");
}
getHibernateTemplate().delete(org);
}
public Organization findOrg(int orgId) {
return (Organization)getHibernateTemplate().load(Organization.class, orgId);
}
public List searchOrgs(int parentId) {
if(parentId == 0){
return getHibernateTemplate().find("select o from Organization o where o.parent is null");}
String hql = "select o from Organization o where o.parent.id = ?";
return getHibernateTemplate().find(hql, parentId);
}
public void updateOrg(Organization org, int parentId) {
if(parentId != 0){
org.setParent(findOrg(parentId));
}
getHibernateTemplate().update(org);
}
}
Organization.class 类也可以调用CLASS ? 这是什么意思呀?这个是尚学堂OA源码里的,这点看不懂?
(Organization)getHibernateTemplate() 前面这个Organization是什么意思? --------------------编程问答-------------------- 强制转换成Organization类型 --------------------编程问答-------------------- public Organization findOrg(int orgId) {
return (Organization)getHibernateTemplate().load(Organization.class, orgId);
}
//这个方法是Organization类型的,所以你返回值也应该是Organization 类型的,但是你getHibernateTemplate().load(Organization.class, orgId)返回类型不是Organization类型,所以要(Organization)强制类型转换。
//load(Organization.class, orgId)这句话意思是load(entityClass,id)第一个参数是指定的是哪个实体类,对应的就是Organization,所以要用Organization.class。
补充:Java , J2ME