欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

实训4

程序员文章站 2022-03-29 14:40:35
...

本次实训创建服务接口和服务接口实现类
创建学校服务接口CollegeService
实训4
创建状态服务接口StatusService
实训4
创建学生服务接口StudentService
实训4
创建用户服务接口UserService
实训4
创建学校服务接口实现类CollegeServiceImpl实训4
对CollegeServiceImpl进行单元测试
package net.zty.student.test;

import net.zty.student.bean.College;
import net.zty.student.service.CollegeService;
import net.zty.student.service.impl.CollegeServicelmpl;
import org.junit.Test;

public class TestCollegeServicelpml {
CollegeService service = new CollegeServicelmpl();

@Test
public void testFindCollegeById(){
College college = service.findCollegeById(1);
System.out.println(“校名” + college.getName());
System.out.println(“校长” + college.getPresident());
System.out.println(“地址” + college.getAddress());
System.out.println(“邮箱” + college.getEmail());
System.out.println(“电话” + college.getTelephone());
}
@Test
public void testUpdateCollege(){
CollegeService service = new CollegeServicelmpl();
College college = service.findCollegeById(1);
college.setPresident(“大王”);
college.setTelephone(“0813-153215”);
int count = service.updateCollege(college);
if(count > 0){
System.out.println(“恭喜,学校记录更新成功!”);
college = service.findCollegeById(1);
System.out.println(college);
}else{
System.out.println(“遗憾学校记录更新失败!”);
}
}
}
创建状态服务接口实现类StatusServiceImpl
实训4
对StatusServiceImpl进行单元测试
package net.zty.student.test;

import net.zty.student.bean.Status;
import net.zty.student.service.StatusService;
import net.zty.student.service.impl.StatusServiceImpl;
import org.junit.Test;

public class TestStatusServiceImpl {
StatusService service = new StatusServiceImpl();
@Test
public void testFindStatusById(){
Status status = service.findStatusById(1);
System.out.println(“作者” + status.getAuthor());
System.out.println(“学校” + status.getCollege());
System.out.println(“版本” + status.getVersion());
System.out.println(“地址” + status.getAddress());
System.out.println(“电话” + status.getTelephone());
System.out.println(“邮箱” + status.getEmail());
}
@Test
public void testUpdateStatus(){
Status status = service.findStatusById(1);
status.setAuthor(“无情”);
status.setTelephone(“15850000000”);
int count = service.updateStatus(status);
if(count > 0){
System.out.println(“恭喜,状态记录更新!”);
status = service.findStatusById(1);
System.out.println(status);
}else{
System.out.println(“遗憾,状态记录更新失败!”);
}
}
}
创建学生服务接口实现类StudentServiceImpl
package net.zty.student.service.impl;

import net.zty.student.bean.Student;
import net.zty.student.dao.StudentDao;
import net.zty.student.dao.impl.StudentDaoImpl;
import net.zty.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<Student> 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<Student> findStudentsByClass(String clazz) {
    return studentDao.findByClass(clazz);
}

@Override
public List<Student> findStudentsByDepartment(String department) {
    return studentDao.findByDepartment(department);
}

@Override
public List<Student> findStudentsByName(String name) {
    return studentDao.findByName(name);
}

@Override
public int updateStudent(Student student) {
    return studentDao.update(student);
}

}
对StudentServiceImpl进行单元测试
实训4
创建用户服务接口实现类UserServiceImpl
package net.zty.student.service.impl;

import net.zty.student.bean.User;
import net.zty.student.dao.UserDao;
import net.zty.student.dao.impl.UserDaolmpl;
import net.zty.student.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService{
private UserDao userDao = new UserDaolmpl();
@Override
public int addUser(User user) {
return userDao.insert(user);
}

@Override
public int deleteUserById(int id) {
    return userDao.deleteById(id);
}

@Override
public List<User> 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);
}

}
实训4

相关标签: 实训