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
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?