业务层将持久层方法调用

主要业务层和持久层的联系

员工实体Bean

package com.project.bean;

import java.sql.Date;
/**
 * 员工信息实体类
 * @author 45470
 *
 */
public class EmployeeBean {
	/**员工id*/
	private int empId;
	/**员工登录名*/
	private String empAccount;
	/**员工登录密码*/
	private String empPwd="123456";
	/**员工姓名*/
	private String empName;
	/**员工性别*/
	private String empSex;
	/**员工文化程度*/
	private String empEdu;
	/**员工出生日期*/
	private Date empBirthday;
	/**员工联系电话*/
	private String empTle;
	/**员工所属专业*/
	private String empProfession;
	/**员工政治面貌*/
	private String empPolitic;
	/**员工家庭住址*/
	private String empAddress;
	/**工作职位id*/
	private int jobId;
	/**职位名称*/
	private String jobName;
	/**员工部门id*/
	private int deptId;
	/**部门名称*/
	private String deptName;
	/**员工入职日期*/
	private Date joinDate=new Date(System.currentTimeMillis());
	/**员工头像文件名称或文件路径*/
	private String imgPath;
	/**职位对象,封装用户登录权限*/
	private JobBean job;
	public EmployeeBean() {
		super();
		// TODO Auto-generated constructor stub
	}

	public EmployeeBean(String empAccount, String empPwd, String empName, String empSex, String empEdu,
			Date empBirthday, String empTle, String empProfession, String empPolitic, String empAddress, int jobId,
			int deptId, Date joinDate,  String imgPath) {
		super();
		this.empAccount = empAccount;
		this.empPwd = empPwd;
		this.empName = empName;
		this.empSex = empSex;
		this.empEdu = empEdu;
		this.empBirthday = empBirthday;
		this.empTle = empTle;
		this.empProfession = empProfession;
		this.empPolitic = empPolitic;
		this.empAddress = empAddress;
		this.jobId = jobId;
		this.deptId = deptId;
	     this.joinDate=joinDate;
		this.imgPath = imgPath;
	}

	public int getEmpId() {
		return empId;
	}
	public void setEmpId(int empId) {
		this.empId = empId;
	}
	public String getEmpAccount() {
		return empAccount;
	}
	public void setEmpAccount(String empAccount) {
		this.empAccount = empAccount;
	}
	public String getEmpPwd() {
		return empPwd;
	}
	public void setEmpPwd(String empPwd) {
		this.empPwd = empPwd;
	}
	public String getEmpName() {
		return empName;
	}
	public void setEmpName(String empName) {
		this.empName = empName;
	}
	public String getEmpSex() {
		return empSex;
	}
	public void setEmpSex(String empSex) {
		this.empSex = empSex;
	}
	public String getEmpEdu() {
		return empEdu;
	}
	public void setEmpEdu(String empEdu) {
		this.empEdu = empEdu;
	}
	public Date getEmpBirthday() {
		return empBirthday;
	}
	public void setEmpBirthday(Date empBirthday) {
		this.empBirthday = empBirthday;
	}
	public String getEmpTle() {
		return empTle;
	}
	public void setEmpTle(String empTle) {
		this.empTle = empTle;
	}
	public String getEmpProfession() {
		return empProfession;
	}
	public void setEmpProfession(String empProfession) {
		this.empProfession = empProfession;
	}
	public String getEmpPolitic() {
		return empPolitic;
	}
	public void setEmpPolitic(String empPolitic) {
		this.empPolitic = empPolitic;
	}
	public String getEmpAddress() {
		return empAddress;
	}
	public void setEmpAddress(String empAddress) {
		this.empAddress = empAddress;
	}
	public int getJobId() {
		return jobId;
	}
	public void setJobId(int jobId) {
		this.jobId = jobId;
	}
	public String getJobName() {
		return jobName;
	}
	public void setJobName(String jobName) {
		this.jobName = jobName;
	}
	public int getDeptId() {
		return deptId;
	}
	public void setDeptId(int deptId) {
		this.deptId = deptId;
	}
	public String getDeptName() {
		return deptName;
	}
	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}
	public Date getJoinDate() {
		return joinDate;
	}
	public void setJoinDate(Date joinDate) {
		this.joinDate = joinDate;
	}
	public String getImgPath() {
		return imgPath;
	}
	public void setImgPath(String imgPath) {
		this.imgPath = imgPath;
	}
	public JobBean getJob() {
		return job;
	}
	public void setJob(JobBean job) {
		this.job = job;
	}

	@Override
	public String toString() {
		return "EmployeeBean [empId=" + empId + ", empAccount=" + empAccount + ", empPwd=" + empPwd + ", empName="
				+ empName + ", empSex=" + empSex + ", empEdu=" + empEdu + ", empBirthday=" + empBirthday + ", empTle="
				+ empTle + ", empProfession=" + empProfession + ", empPolitic=" + empPolitic + ", empAddress="
				+ empAddress + ", jobId=" + jobId + ", jobName=" + jobName + ", deptId=" + deptId + ", deptName="
				+ deptName + ", joinDate=" + joinDate + ", imgPath=" + imgPath + ", job=" + job + "]";
	}

}

  

持久层接口

package com.project.dao;

import java.util.List;

import com.project.bean.DeptBean;
import com.project.bean.EmployeeBean;
import com.project.bean.JobBean;

/**
 * 员工类持久化接口
 * @author Administrator
 *
 */
public interface IEmployeeDao {
	/**
	 * 登录方法,查询拥有用户名和密码的对象,若果没有返回空
	 * @param userName 用户登录名
	 * @param pwd 密码
	 * @return 拥有用户名和密码的员工对象,如果没有返回空
	 */
	public EmployeeBean login(String userName,String pwd);
	/**
	 * 添加员工
	 * @param bean 员工对象
	 */
	public void add(EmployeeBean bean);
	/**
	 * 按id删除员工
	 * @param emId
	 */
	public void del(int emId);
	/**
	 * 按照员工id查询员工信息,包含职位名称,部门名称
	 * @param emId
	 * @return
	 */
	public EmployeeBean findById(int emId);

	/**
	 * 按照员工的id,修改员工的所在部门id,联系方式,政治面貌,工作职位
	 * @param emId 员工的id
	 * @param emTel 员工新的联系方式
	 * @param deptId 员工新的部门id
	 * @param politic 员工新的政治面貌
	 * @param jobId 员工新的职位
	 */
	public void update(int emId,String emTel,
			int deptId,String politic,int jobId);
	/**
	 * 动态查询员工信息,姓名为模糊查询
	 * @param enName
	 * @param emEdu
	 * @param emDept
	 * @param jobName
	 * @return
	 */
	public List<EmployeeBean> findByItem(String enName,String emEdu,String emDept,String jobName );
	/**
	 * 通过部门id,连表查询部门所有员工,部门表左外连接
	 * @param deptId
	 * @return
	 */
	public List<EmployeeBean> findByDeptId(int deptId);
	/**
	 *连接学校表,部门表,员工表,按照学校id查询负责部门的所有员工
	 * @param schoolId 学校id
	 * @return 员工对象集合
	 */
	public List<EmployeeBean> findBySchool(int schoolId);
	/**
	 * 按照id修改密码
	 * @param id 员工id
	 * @param newPwd xinmi
	 */
	public void updatePwd(int id,String newPwd);
}

 持久层实现类

package com.project.impl;

import java.sql.Connection;
import java.sql.Date;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.project.bean.EmployeeBean;
import com.project.dao.IEmployeeDao;

/**
 * 员工持久实现类
 * @author Administrator
 *
 */
public class EmployeeDaoImpl extends BaseDao implements IEmployeeDao {

	public static void main(String[] args) {
		IEmployeeDao dao=new EmployeeDaoImpl();
	    //System.out.println(dao.login("aaa", "123"));
		//dao.add(new EmployeeBean("tuhao","2222", "java",  "男", "本科", Date.valueOf("2001-02-01"), "12323244", "篮球", "团员", "北京", 1, 1, new Date(System.currentTimeMillis()), "c:/djsdasj"));
		//dao.del(1);
		//System.out.println(dao.findById(2));
	    //dao.update(2,"22222",3,"党员", 3);
	    //System.out.println(dao.findByItem("","大专", null,null));
		//dao.updatePwd(3, "22");
		//System.out.println( dao.findByDeptId(4));
	  // System.out.println(dao.findBySchool(3));
	}

	@Override
	public EmployeeBean login(String userName, String pwd) {
		EmployeeBean bean=null;

		this.setConnection();
		try {
			ps=con.prepareStatement("select*from t_employee where em_account=? and em_pwd=?");
			ps.setString(1, userName);
			ps.setString(2, pwd);
			rs=ps.executeQuery();
		if(rs.next()){
			bean=new EmployeeBean();
			bean.setEmpId(rs.getInt("em_id"));
			bean.setEmpAccount(rs.getString("em_account"));
			bean.setEmpPwd(rs.getString("em_pwd"));
			bean.setEmpName(rs.getString("em_name"));
			bean.setEmpSex(rs.getString("em_sex"));
			bean.setEmpEdu(rs.getString("em_edu"));
			bean.setEmpBirthday(rs.getDate("em_birthday"));
			bean.setEmpTle(rs.getString("em_tel"));
			bean.setEmpProfession(rs.getString("em_profession"));
			bean.setEmpPolitic(rs.getString("em_politic"));
			bean.setEmpAddress(rs.getString("em_address"));
			bean.setJobId(rs.getInt("em_jobId"));
		    bean.setDeptId(rs.getInt("em_deptId"));
		    bean.setImgPath(rs.getString("em_imgPath"));
		    bean.setJoinDate(rs.getDate("em_joinDate"));			

		}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			this.closeConnection();
		}

		return bean;

	}

	@Override
	public void add(EmployeeBean bean) {
		this.setConnection();
		try {
			ps=con.prepareStatement("insert into t_employee(em_account,em_pwd,em_name,em_sex,em_edu,em_birthday,"
					+ "em_tel,em_profession,em_politic,em_address,em_jobId,em_deptId,em_joindate,em_imgPath) "
					+ "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
			ps.setString(1,bean.getEmpAccount());
			ps.setString(2,bean.getEmpPwd());
			ps.setString(3,bean.getEmpName());
			ps.setString(4,bean.getEmpSex());
			ps.setString(5,bean.getEmpEdu());
			ps.setDate(6,bean.getEmpBirthday());
			ps.setString(7,bean.getEmpTle());
			ps.setString(8,bean.getEmpProfession());
			ps.setString(9, bean.getEmpPolitic());
			ps.setString(10, bean.getEmpAddress());
			ps.setInt(11,bean.getJobId());
			ps.setInt(12, bean.getDeptId());
			ps.setDate(13,bean.getJoinDate());
			ps.setString(14,bean.getImgPath());
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			this.closeConnection();
		}

	}

	@Override
	public void del(int emId) {
		this.setConnection();
		try {
			ps=con.prepareStatement("delete from t_employee where em_id=?");
			ps.setInt(1, emId);
			ps.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			this.closeConnection();
		}

	}

	@Override
	public EmployeeBean findById(int emId) {
		this.setConnection();
		EmployeeBean bean=new EmployeeBean();
		try {
			ps=con.prepareStatement("SELECT e.*,j.job_name,d.dept_name FROM t_employee e,t_job j,t_dept d WHERE e.em_jobId=j.job_id AND e.em_deptId=d.dept_id AND  em_id =?");
			ps.setInt(1, emId);
			rs=ps.executeQuery();
			if(rs.next()){

				bean.setEmpId(rs.getInt("em_id"));
				bean.setEmpAccount(rs.getString("em_account"));
				bean.setEmpPwd(rs.getString("em_pwd"));
				bean.setEmpName(rs.getString("em_name"));
				bean.setEmpSex(rs.getString("em_sex"));
				bean.setEmpEdu(rs.getString("em_edu"));
				bean.setEmpBirthday(rs.getDate("em_birthday"));
				bean.setEmpTle(rs.getString("em_tel"));
				bean.setEmpProfession(rs.getString("em_profession"));
				bean.setEmpPolitic(rs.getString("em_politic"));
				bean.setEmpAddress(rs.getString("em_address"));
				bean.setJobId(rs.getInt("em_jobId"));
			    bean.setDeptId(rs.getInt("em_deptId"));
			    bean.setImgPath(rs.getString("em_imgPath"));
			    bean.setJoinDate(rs.getDate("em_joinDate"));
			    bean.setDeptName(rs.getString("dept_name"));
			    bean.setJobName(rs.getString("job_name"));

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally {
			this.closeConnection();
		}
		return bean;
	}

	@Override
	public void update(

			int emId, String emTel, int deptId, String politic, int jobId) {
		this.setConnection();
		try {
			ps=con.prepareStatement("update t_employee set em_tel=?,em_deptId=?,em_politic=?,em_jobId=? where em_id=? ");
			ps.setString(1, emTel);
			ps.setInt(2, deptId);
			ps.setString(3,politic);
			ps.setInt(4, jobId);
			ps.setInt(5, emId);
		    ps.executeUpdate();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			this.closeConnection();
		}

	}

	@Override
	public List<EmployeeBean> findByItem(String enName, String emEdu, String emDept, String jobName) {
		this.setConnection();
		List<EmployeeBean> list =new ArrayList<EmployeeBean>();
		String sql="SELECT e.*,d.dept_name,j.job_name FROM t_employee e,t_dept d,t_job j WHERE e.em_deptId=d.dept_id AND e.em_jobId=j.job_id ";

		if(enName!=null&&enName.length()!=0){
			sql+=" and e.em_name like ‘%"+enName+"%‘ ";
		}
		if(emEdu!=null&&emEdu.length()!=0){
			sql+=" and e.em_edu=‘"+emEdu+"‘ " ;
		}
		if(emDept!=null&&emDept.length()!=0){
			sql+=" and d.dept_name like ‘%"+emDept+"&‘ ";
		}
		if(jobName!=null&&jobName.length()!=0){
			sql+=" and j.job_namelike ‘%"+jobName+"&‘  ";
		}

		try {
			ps=con.prepareStatement(sql);
			rs=ps.executeQuery();
			while(rs.next()){
				EmployeeBean bean=new EmployeeBean();
				bean.setEmpId(rs.getInt("em_id"));
				bean.setEmpAccount(rs.getString("em_account"));
				bean.setEmpPwd(rs.getString("em_pwd"));
				bean.setEmpName(rs.getString("em_name"));
				bean.setEmpSex(rs.getString("em_sex"));
				bean.setEmpEdu(rs.getString("em_edu"));
				bean.setEmpBirthday(rs.getDate("em_birthday"));
				bean.setEmpTle(rs.getString("em_tel"));
				bean.setEmpProfession(rs.getString("em_profession"));
				bean.setEmpPolitic(rs.getString("em_politic"));
				bean.setEmpAddress(rs.getString("em_address"));
				bean.setJobId(rs.getInt("em_jobId"));
			    bean.setDeptId(rs.getInt("em_deptId"));
			    bean.setImgPath(rs.getString("em_imgPath"));
			    bean.setJoinDate(rs.getDate("em_joinDate"));

				list.add(bean);
			}

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			this.closeConnection();
		}

		return list;
	}

	@Override
	public List<EmployeeBean> findByDeptId(int deptId) {
		List<EmployeeBean> list=new ArrayList<EmployeeBean>();
		this.setConnection();
		try {// 我SELECT e.* FROM t_employee e,t_dept d WHERE e.em_deptId=d.dept_id AND d.dept_id=?
			ps=con.prepareStatement("select *from t_employee  where em_deptId=?");

			ps.setInt(1, deptId);
			rs=ps.executeQuery();
			while(rs.next()){
				EmployeeBean bean=new EmployeeBean();
				bean.setEmpId(rs.getInt("em_id"));
				bean.setEmpAccount(rs.getString("em_account"));
				bean.setEmpPwd(rs.getString("em_pwd"));
				bean.setEmpName(rs.getString("em_name"));
				bean.setEmpSex(rs.getString("em_sex"));
				bean.setEmpEdu(rs.getString("em_edu"));
				bean.setEmpBirthday(rs.getDate("em_birthday"));
				bean.setEmpTle(rs.getString("em_tel"));
				bean.setEmpProfession(rs.getString("em_profession"));
				bean.setEmpPolitic(rs.getString("em_politic"));
				bean.setEmpAddress(rs.getString("em_address"));
				bean.setJobId(rs.getInt("em_jobId"));
			    bean.setDeptId(rs.getInt("em_deptId"));
			    bean.setImgPath(rs.getString("em_imgPath"));
			    bean.setJoinDate(rs.getDate("em_joinDate"));
				list.add(bean);

			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			this.closeConnection();
		}

		return list;
	}

	@Override
	public List<EmployeeBean> findBySchool(int schoolId) {
		List<EmployeeBean> list=new ArrayList<EmployeeBean>();
		this.setConnection();
		try {//我SELECT e.* FROM t_employee e,t_school s WHERE  e.em_id=s.sch_functionary AND  sch_id=?
			ps=con.prepareStatement("SELECT e.* FROM t_employee e,t_dept d,t_school s WHERE e.em_deptId=d.dept_id AND s.sch_dept=d.dept_id AND s.sch_id=?");

		ps.setInt(1, schoolId);
		rs=ps.executeQuery();
		while(rs.next()){
			EmployeeBean bean=new EmployeeBean();
			bean.setEmpId(rs.getInt("em_id"));
			bean.setEmpAccount(rs.getString("em_account"));
			bean.setEmpPwd(rs.getString("em_pwd"));
			bean.setEmpName(rs.getString("em_name"));
			bean.setEmpSex(rs.getString("em_sex"));
			bean.setEmpEdu(rs.getString("em_edu"));
			bean.setEmpBirthday(rs.getDate("em_birthday"));
			bean.setEmpTle(rs.getString("em_tel"));
			bean.setEmpProfession(rs.getString("em_profession"));
			bean.setEmpPolitic(rs.getString("em_politic"));
			bean.setEmpAddress(rs.getString("em_address"));
			bean.setJobId(rs.getInt("em_jobId"));
		    bean.setDeptId(rs.getInt("em_deptId"));
		    bean.setImgPath(rs.getString("em_imgPath"));
		    bean.setJoinDate(rs.getDate("em_joinDate"));
			list.add(bean);

		}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			this.closeConnection();
		}

		return list;
	}

	@Override
	public void updatePwd(int id, String newPwd) {
		this.setConnection();
		try {
			ps=con.prepareStatement("update t_employee set em_pwd=? where em_id=?");
			ps.setString(1, newPwd);
			ps.setInt(2, id);
			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			this.closeConnection();
		}
	}

}

  业务层接口

package com.project.service;

import java.util.List;

import com.project.bean.EmployeeBean;
/**
 * 员工实体类业务接口
 * @author Administrator
 *
 */
public interface IEmployeeService {
	/**
	 * 登录业务。查询拥有用户名和密码的对象,如果没找到返回空
	 * 如果登录成功,封装职位对象
	 * @param userName 用户名
	 * @param pwd 密码
	 * @return 拥有用户密码的员工对象,如果没有返回null
	 */
	public EmployeeBean login(String userName,String pwd);
	/**
	 * 添加新员工
	 * @param bean 员工对象
	 */
	public void add(EmployeeBean bean);
	/**
	 * 按员工id删除员工,删除员工之前,先将该员工负责的学校,负责人外键设置为null
	 * @param emId 员工id
	 */
	public void del(int emId);
	/**
	 * 通过id查询员工,同时查询部门的名称和职位的名称
	 * @param emId 员工id
	 * @return 员工对象
	 */
	public EmployeeBean findById(int emId);
	/**
	 * 按照选择员工的id修改员工的所在部门,联系方式,政治面貌,工作职位
	 * @param emId 所选择员工的id
	 * @param emTel 员工新的联系方式
	 * @param deptId 员工新的部门id
	 * @param politic 员工新的政治面貌
	 * @param jobId 员工新的职位id
	 */
	public void update(int emId,String emTel,int deptId,String politic,int jobId);
	/**
	 * 动态条件查询员工,同时查询员工的部门名称和职位名称
	 * @param emName 按员工姓名模糊查找
	 * @param emEdu 按文化程度查找
	 * @param emDept 按所在部门查询
	 * @param jobName 按工作职位查询
	 * @return 员工对象集合
	 */
	public List<EmployeeBean> findByItem(String emName,String emEdu,String emDept,String jobName);
	/**
	 * 通过部门id查询部门所有员工
	 * @param deptId 部门id
	 * @return 员工对象集合
	 */
	public List<EmployeeBean> findByDeptId(int deptId);
	/**
	 * 查询指定id的学校,负责部门所有员工
	 * @param schoolId 学校ID
	 * @return 员工集合
	 */
	public List<EmployeeBean> findBySchool(int schoolId);
	/**
	 * 按id修改密码
	 * @param id 员工id
	 * @param newPwd 员工新密码
	 */
	public void updatePwd(int id,String newPwd);
}

  

业务层实现类

package com.project.service.impl;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

import com.project.bean.EmployeeBean;
import com.project.bean.LogBean;
import com.project.dao.IEmployeeDao;
import com.project.dao.IJobDao;
import com.project.dao.ILogDao;
import com.project.dao.ISchoolDao;
import com.project.impl.EmployeeDaoImpl;
import com.project.impl.JobDaoImpl;
import com.project.impl.LogDaoImpl;
import com.project.impl.SchoolDaoImpl;
import com.project.service.IEmployeeService;

import sun.java2d.pipe.SpanShapeRenderer.Simple;
/**
 * 员工业务接口实现类
 * @author Administrator
 *
 */
public class EmployeeServiceImpl implements IEmployeeService {

private IEmployeeDao  emDao=new EmployeeDaoImpl();
private IJobDao jobDao=new  JobDaoImpl();
private ISchoolDao schDao=new SchoolDaoImpl();
private ILogDao logDao=new  LogDaoImpl();

public static void main(String[] args) {
	IEmployeeService service=new EmployeeServiceImpl();
	//System.out.println(service.login("jjj","123"));
}
	@Override
	public EmployeeBean login(String userName, String pwd) {
	   EmployeeBean bean=emDao.login(userName, pwd);

	   if(bean!=null){
		   bean.setJob(jobDao.findById(bean.getJobId()));
		   SimpleDateFormat sd=new SimpleDateFormat("HH:hh");
		   String str="用户"+userName+"在"+sd.format(new Date(System.currentTimeMillis()))+"登录系统";

		   LogBean logBean=new LogBean();
		   logBean.setLogContent(str);
		   logDao.add(logBean);

	   }

		return bean;
	}

	@Override
	public void add(EmployeeBean bean) {
		emDao.add(bean);

	}

	@Override
	public void del(int emId) {

		schDao.updateSchoolByEmIdNULL(emId);
		emDao.del(emId);
	}

	@Override
	public EmployeeBean findById(int emId) {

		return emDao.findById(emId);
	}

	@Override
	public void update(int emId, String emTel, int deptId, String politic, int jobId) {
		emDao.update(emId, emTel, deptId, politic, jobId);

	}

	@Override
	public List<EmployeeBean> findByItem(String emName, String emEdu, String emDept, String jobName) {

		return emDao.findByItem(emName, emEdu, emDept, jobName);
	}

	@Override
	public List<EmployeeBean> findByDeptId(int deptId) {

		return emDao.findByDeptId(deptId);
	}

	@Override
	public List<EmployeeBean> findBySchool(int schoolId) {

		return emDao.findBySchool(schoolId);
	}

	@Override
	public void updatePwd(int id, String newPwd) {
	emDao.updatePwd(id, newPwd);

	}

}

  

 

时间: 2024-10-08 22:10:29

业务层将持久层方法调用的相关文章

面向对象——三层架构(表现层、业务层、持久层)

三层架构:即表现层.业务层.持久层. ① 持久层:采用DAO模式,建立实体类和数据库表映射(ORM映射).也就是哪个类对应哪个表,哪个属性对应哪个列.持久层 的目的就是,完成对象数据和关系数据的转换. ② 业务层:采用事务脚本模式.将一个业务中所有的操作封装成一个方法,同时保证方法中所有的数据库更新操作,即保证同时成 功或同时失败.避免部分成功部分失败引起的数据混乱操作. ③ 表现层:采用MVC模式. M称为模型,也就是实体类.用于数据的封装和数据的传输. V为视图,也就是GUI组件,用于数据的

Spring的四个基本注解annotation(控制层,业务层,持久层) @Component、@

SpringMVC中四个基本注解: @Component.@Repository   @Service.@Controller 看字面含义,很容易却别出其中三个: @Controller    控制层,就是我们的action层 @Service        业务逻辑层,就是我们的service或者manager层 @Repository  持久层,就是我们常说的DAO层 而@Component  (字面意思就是组件),它在你确定不了事哪一个层的时候使用. 其实,这四个注解的效果都是一样的,Sp

表现层(jsp)、持久层(类似dao)、业务层(逻辑层、service层)、模型(javabean)、控制层(action)

转自:http://www.blogjava.net/jiabao/archive/2007/04/08/109189.html 为了实现web层(struts)和持久层(Hibernate)之间的松散耦合,我们采用业务代表(Business Delegate)和DAO(Data Access Object)两种模式.DAO模式为了减少业务逻辑和数据访问逻辑之间的耦合,当一个持久曾框架被应用时,该模式将会减少业务对象和该框架之间的耦合,这样我们可以不修改业务对象而选择不同的持久层框架的实现.实际

model ,orm,dao,service,持久层 ,mvc 这些名词在java中的概念?

这些概念不针对某个特定的编程语言. view层:结合control层,显示前台页面. control层:业务模块流程控制,调用service层接口. service层:业务操作实现类,调用dao层接口. dao层:数据业务处理,持久化操作 model层:pojo,OR maping,持久层 借别人一张图,希望题主能理清楚层间关系:  企业应用开发中,可以将系统分为三层:表示层.业务层.持久层,就是所谓的三层架构.三层各有各的架构模式.其中表示层常用架构就是MVC,业务层常用架构模式分为事务脚本模

一种好的持久层开发方法——建立BaseDao和BaseDaoImpl

使用hibernate开发持久层时,我们会发现:虽然entity类的含义和需求不同,其对应的Dao层类对应的方法也是不同的.但是有许多方法操作确实相同的.比如实体的增加,删除,修改更新,以及许多常用的查询方法.这些都是可复用的.因此可以把这些操作写在一个BaseDao中,其他的dao都继承于这个Dao.每个子dao只写与自己的业务相关的方法,这样可以提高代码的复用,增加了开发效率,也方便今后可能的扩展.下面是我在我的项目中使用的BaseDao和BaseDaoImpl的使用方法.仅供参考: Bas

【转载】 JAVA三层架构,持久层,业务层,表现层的理解

JAVA三层架构,持久层,业务层,表现层的理解 转载:http://blog.csdn.net/ljf_study/article/details/64443653 SSH: Struts(表示层)+Spring(业务层)+Hibernate(持久层) Struts: Struts是一个表示层框架,主要作用是界面展示,接收请求,分发请求. 在MVC框架中,Struts属于VC层次,负责界面表现,负责MVC关系的分发. (View:沿用JSP,HTTP,Form,Tag,Resourse : Co

请问JAVA三层架构,持久层,业务层,表现层,都该怎么理解?和MVC三层模型有什么区别

持久层用来固化数据,如常说的DAO层,操作数据库将数据入库业务层用来实现整体的业务逻辑 如 前台获得了数据,逻辑层去解析这些数据,效验这些数据等操作表现层很好解释  你现在看到的网页 一些界面 都属于表现层的东西可以用一些Html,jsp,Swing来实现至于mvc么对应的是 model(模型) view(视图) Controller(控制)在javaweb中就很好理解了再XX系统中,前台页面属于view 贯穿前台后台持久层的一套模型就是model(EJB,Spring来实现)  而连接前台后台

bboss持久层设置数据库查询fetchsize参数方法

jdbc驱动程序api提供了指定了查询语句fetchsize的方法,有些数据库(比如oracle)本身提供了fetchsize的默认值,这样进行大量数据查询时,不会因为返回的结果集太大导致jvm爆掉,有些数据库可能没有默认设置fetchsize,因此需要手动指定.bboss持久层设置数据库查询fetchsize参数方法很简单,只要在poolman.xml文件的datasource中指定一个queryfetchsize参数即可,如果不指定就采用数据库驱动提供的默认值. 设置queryfetchsi

spring/springMVC/mybatis(持久层、业务层、控制层思路小结)

准备工作: ## 7 导入省市区数据到数据库中 1. 从FTP下载SQL脚本文件 2. 把脚本文件移动到易于描述绝对路径的位置 3. 进入MySQL控制台 4. 使用`tedu_store`数据库 5. 运行`source e:\t_dict.sql`以执行该脚本文件    (  linux下的命令是  source /home/soft01/桌面/t_dict.sql;) -------------------------------------------------------------