您当前的位置: 首页 > 

梁云亮

暂无认证

  • 1浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

企业员工管理系统 四:服务层

梁云亮 发布时间:2020-01-09 15:47:25 ,浏览量:1

service 接口 DeptService.java
public interface DeptService {

	/**
	 *  将Dept所对应的JSON字符串baocun到相应的文件中
	 * @param dept
	 * @return 返回true表示更新,false表示添加
	 * @throws IOException
	 */
	public boolean addDept(Dept dept)throws IOException;
	
	/**
	 *   按照 deptno更新数据:参数dept的deptno如果在文件中存在就更新,否则加入
	 * @param dept
	 * @return
	 * @throws IOException
	 */
	public boolean updateDept(Dept dept) throws IOException;
	
	/**
	 *   删除参数deptno制定的部门
	 * @param deptno
	 * @return 存在并且删除成功返回;true,不存在返回false
	 * @throws IOException
	 */
	public boolean deleteDeptByDeptno(Integer deptno) throws IOException;//参数使用引用数据类型
	
	public Dept getDeptByDeptno(Integer deptno) throws IOException;
	
	public Dept getDeptByDname(String dname) throws IOException;
	
	public List getAllDept() throws IOException;
	
}
EmpService.java
public interface EmpService {

	public boolean addEmp(Emp emp) throws IOException;

	public boolean updateEmp(Emp emp) throws IOException;

	public boolean deleteEmpByEmpno(Integer empno) throws IOException;// 参数使用引用数据类型

	public Emp getEmpByEmpno(Integer empno) throws IOException;

	public Emp getEmpByEname(String ename) throws IOException;

	public List getEmpByDeptno(Integer deptno) throws IOException;

	public List getAllEmp() throws IOException;
	
}
ManagerService.java
public interface ManagerService {

	public boolean login(String name,String password);
	
}
实现类 DeptServiceImpl.java
public class DeptServiceImpl implements DeptService {

	File file = new File(GlobalConst.DB_NAME + "/" + GlobalConst.DEPT_TABLE_NAME); //Dept数据所保存到的文件

	@Override
	public boolean addDept(Dept dept)  {
		try {
			FileWriter writer = new FileWriter(file, true); // true追加, false覆盖
			BufferedWriter br = new BufferedWriter(writer);
			br.write(JSON.toJSONString(dept) + "\n"); /将Dept所对应的JSON数据保存到文件中
			if (br != null) {
				br.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
			return false; // 失败返回false
		} 
		return true; // 成功返回true
	}

	@Override
	public boolean updateDept(Dept dept) throws IOException {//存在更新,否则保存
		List allDept = getAllDept(); //获取文件中保存的所有的部门信息
		boolean flag = false; // false表示数据不存在
		for(int i =0;i            
关注
打赏
1665409997
查看更多评论
0.0427s