package day0603; /* 业务层 */ public class StudentService { private StudentDao studentDao = new StudentDao(); public String addStudent(Student student) { //判断学号是否冲突 String id = student.getId(); boolean isExistsResult = isExists(id); return studentDao.addStudent(student); } public boolean isExists(String id) { Student[] students = studentDao.getStudents(); for (Student s:students){ if (s.getId().equals(id)) { return true; } } return false; } public String deleteStudentById(String id) { return studentDao.deleteStudentById(id); } public Student[] selectAllStudents() { return studentDao.getStudents(); } public String updateStudent(Student student) { return studentDao.updateStudent(student); } public Student selectOneById(String id) { return studentDao.selectOneById(id); } }将代码中全部student替换为teacher
时间: 2024-02-14 20:10:39 浏览: 61
业务逻辑层调用数据访问层方法-C#三层架构5
替换后的代码如下:
```java
package day0603;
/* 业务层 */
public class TeacherService {
private TeacherDao teacherDao = new TeacherDao();
public String addTeacher(Teacher teacher) {
//判断工号是否冲突
String id = teacher.getId();
boolean isExistsResult = isExists(id);
return teacherDao.addTeacher(teacher);
}
public boolean isExists(String id) {
Teacher[] teachers = teacherDao.getTeachers();
for (Teacher t:teachers){
if (t.getId().equals(id)) {
return true;
}
}
return false;
}
public String deleteTeacherById(String id) {
return teacherDao.deleteTeacherById(id);
}
public Teacher[] selectAllTeachers() {
return teacherDao.getTeachers();
}
public String updateTeacher(Teacher teacher) {
return teacherDao.updateTeacher(teacher);
}
public Teacher selectOneById(String id) {
return teacherDao.selectOneById(id);
}
}
```
阅读全文