⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deptdao.java

📁 基于J2EE的办公自动化系统。实现流程定义流程办理等。运用了hibernate+struts+spring框架综合运用的系统。
💻 JAVA
字号:
package com.oa.module.office.dept;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.oa.util.XPage;

/**
 * 操作数据库的DAO类
 * @author czpeng
 *
 */
public class DeptDAO implements InDeptDAO{

	
	private SessionFactory sfactory;
	
	//JDBC连接数据库方法
	private JdbcTemplate jdbcTemplate;//JDBC

	/* (非 Javadoc)
	 * @see com.oa.module.office.dept.InDeptDAO#getDeptlist(int, int, com.oa.module.office.dept.Tdept)
	 */
	public XPage getDeptlist(int currentPage, int count, Tdept info) {

		String content ="select rownum as rnum,d.*,u.uname from tdept d left join tuser u on d.uno=u.uno where 1=1";
		
		String path="dept.do?method=query&";		

		String sql ="SELECT * FROM("+content+") m WHERE m.rnum<="+currentPage*count+ " AND m.rnum>"+(currentPage-1)*count;
		
		XPage page = new XPage();
		//开始设置xpage
		page.setCurrentPage(currentPage);
		page.setCount(count);

		//设置分页路径
		page.setPath(path);

		List list = null;
		List list1 = null;
		try {
			list1 = jdbcTemplate.queryForList(content);
			list = jdbcTemplate.queryForList(sql);
			
			int allcount = list1.size();
			page.setAllCount(allcount);
			
			page.setList(list);
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		return page;
	}		

	public SessionFactory getSfactory() {
		return sfactory;
	}

	public void setSfactory(SessionFactory sfactory) {
		this.sfactory = sfactory;
	}

	
	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	/** 
	 * 获取全部用户信息
	 * return list
	 */
	public List getUser() {		
		String hql = "select a from Tuser a where 1=1";			
		List list = null;
		Session session = null;
		Query query = null;
		
		try {
			session = sfactory.openSession();
			query = session.createQuery(hql);
			
			list = query.list();			
			session.flush();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}
		return list;
	}

	/** 
	 * 添加用户信息
	 * return boolean
	 */
	public boolean addList(Tdept info) {		
		HibernateTemplate ht = new HibernateTemplate(this.sfactory);
		
		try {
			ht.save(info);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	/** 
	 * 修改部门信息
	 */
	public boolean editList(Tdept info) {
		HibernateTemplate ht = new HibernateTemplate(this.sfactory);
		
		try {
			ht.update(info);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	/** 
	 * 用部门编号查询部门
	 */
	public Tdept getDeptById(String did) {		
		HibernateTemplate ht = new HibernateTemplate(this.sfactory);
		Tdept dept = null;		
		try {			
			dept = (Tdept)ht.get(Tdept.class,did);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dept;
	}

	/** 
	 * 部门恢复
	 */
	public boolean openDept(Tdept info) {
		HibernateTemplate ht = new HibernateTemplate(this.sfactory);
		try {
			ht.update(info);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	/** 
	 * 部门冻结
	 */
	public boolean closeDept(Tdept info) {
		HibernateTemplate ht = new HibernateTemplate(this.sfactory);
		try {
			ht.update(info);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	/** 
	 * 用部门名称查询用户信息
	 */
	public boolean getDeptByName(String dname) {
		List list = null;
		String sql = "select * from tdept where dname='"+dname+"'";
		list = jdbcTemplate.queryForList(sql);
		if(list.size()<=0){
			return false;
		}else{
			return true;
		}
	}
	
	/** 
	 * 用部门编号查询用户信息
	 */
	public boolean getUserForDid(String did) {
		List list = null;
		String sql = "select *  from tdept d left join tuser u on d.did = u.did where u.uislocked='0' and d.did='"+did+"'";
		list = jdbcTemplate.queryForList(sql);
		if(list.size()<=0){
			return false;
		}else{
			return true;
		}
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -