第四次实训课
第四次实训课
一、创建服务接口
在net.dlj.student包里创建service子包 创建学校服务接口CollegeService
创建状态服务接口StatusService
创建学生服务接口StudentService
创建用户服务接口UserService
二、
创建服务接口实现类
1.在net.dlj.student.service包里创建impl子包
创建学校服务接口实现类CollegeServiceImpl
在net.dlj.student.test包里创建测试类TestCollegeServiceImpl
编写测试方法testFindCollegeById()
编写测试方法testUpdateCollege()
2.创建状态服务接口实现类StatusServiceImpl
在net.dlj.student.test包里创建测试类TestStatusServiceImpl
编写测试方法testFindStatusById()
编写测试方法testUpdateStatus()
3.创建学生服务接口实现类StudentServiceImpl
package net.dlj.student.service.impl;
import net.dlj.student.bean.Student;
import net.dlj.student.dao.StudentDao;
import net.dlj.student.dao.impl.StudentDaoImpl;
import net.dlj.student.service.StudentService;
import java.util.List;
import java.util.Vector;
public class StudentServiceImpl implements StudentService {
private StudentDao studentDao = new StudentDaoImpl();
@Override
public int addStudent(Student student) {
return studentDao.insert(student);
}
@Override
public int deleteStudentById(String id) {
return studentDao.deleteById(id);
}
@Override
public int deleteStudentsByClass(String clazz) {
return studentDao.deleteByClass(clazz);
}
@Override
public int deleteStudentsByDepartment(String department) {
return studentDao.deleteByDepartment(department);
}
@Override
public List findAllStudents() {
return studentDao.findAll();
}
@Override
public Vector findRowsByClass() {
return studentDao.findRowsByClass();
}
@Override
public Vector findRowsByDepartment() {
return studentDao.findRowsByDepartment();
}
@Override
public Vector findRowsBySex() {
return studentDao.findRowsBySex();
}
@Override
public Student findStudentById(String id) {
return studentDao.findById(id);
}
@Override
public List findStudentsByClass(String clazz) {
return studentDao.findByClass(clazz);
}
@Override
public List findStudentsByDepartment(String department) {
return studentDao.findByDepartment(department);
}
@Override
public List findStudentsByName(String name) {
return studentDao.findByName(name);
}
@Override
public int updateStudent(Student student) {
return studentDao.update(student);
}
}
在net.dlj.student.test包里创建测试类TestStudentServiceImpl
编写测试方法testFindStudentsByName()
(1)编写测试方法testAddStudent()
(2)编写测试方法testDeleteStudentById()
(3)编写测试方法testDeleteStudentsByClass()
(4)编写测试方法testDeleteStudentsByDepartment()
(5)编写测试方法testUpdateStudent()
(6)编写测试方法testFindStudentById()
(7)编写测试方法testFindAllStudents()
(8)编写测试方法testFindStudentsByClass()
(9)编写测试方法testFindStudentsByDepartment()
(10)编写测试方法testFindRowsBySex()
(11)编写测试方法testFindRowsByClass()
(12)编写测试方法testFindRowsByDepartment()
4、创建用户服务接口实现类UserServiceImpl
*package net.dlj.student.service.impl;
import net.dlj.student.bean.User;
import net.dlj.student.dao.UserDao;
import net.dlj.student.dao.impl.UserDaoImpl;
import net.dlj.student.service.UserService;
import java.util.List;
public class UserServiceImpl implements UserService {
private UserDao userDao = new UserDaoImpl();
@Override
public int addUser(User user) {
return userDao.insert(user);
}
@Override
public int deleteUserById(String id) {
return userDao.deleteById(id);
}
@Override
public List findAllUsers() {
return userDao.findAll();
}
@Override
public User findUserById(int id) {
return userDao.findById(id);
}
@Override
public User login(String username, String password) {
return userDao.login(username, password);
}
@Override
public int updateUser(User user) {
return userDao.update(user);
}
@Override
public boolean isUsernameExisted(String username) {
return userDao.isUsernameExisted(username);
}
}*
在net.dlj.student.test包里创建测试类TestUserServiceImpl
编写测试方法testLogin()
(1)编写测试方法testIsUsernameExisted()
(2)编写测试方法testAddUser()
(3)编写测试方法testDeleteUserById()
(4)编写测试方法testUpdateUser()
(5)编写测试方法testFindUserById()
(6)编写测试方法testFindAllUsers()