第四次Java实训课总结

实现步骤

一、创建服务接口

1.创建学校服务接口

在这里插入图片描述

2.创建状态服务接口

在这里插入图片描述

3.创建学生服务接口

在这里插入图片描述

4.创建用户服务接口

在这里插入图片描述

二、创建服务接口实现类

1.创建学校服务接口实现类

package net.zhj.student.service.impl;

import net.zhj.student.bean.College;
import net.zhj.student.dao.CollegeDao;
import net.zhj.student.dao.impl.CollegeDaoImpl;
import net.zhj.student.service.CollgeService;

/**
 * 功能:学校服务接口实现类
 * 作者:朱虹菊
 * 日期:2020年07月08日
 */
public class CollegeServiceImpl implements CollgeService {
   
    private CollegeDao collegeDao = new CollegeDaoImpl();

    @Override
    public College findCollegeById(int id) {
   
        return collegeDao.findById(id);
    }

    @Override
    public int updateCollege(College college) {
   
        return collegeDao.update(college);
    }
}

对CollegeServiceImpl进行单元测试

1.1 编写测试方法testFindCollegeById()
package net.zhj.student.test;

import net.zhj.student.bean.College;
import net.zhj.student.service.CollgeService;
import net.zhj.student.service.impl.CollegeServiceImpl;
import org.junit.Test;

/**
 * 功能:测试学校服务接口实现类
 * 作者:朱虹菊
 * 日期:2020年07月08日
 */
public class TestCollegeServiceImpl {
   
    CollgeService service = new CollegeServiceImpl();

    @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());
    }
}    

运行结果,如下:
在这里插入图片描述

1.2 编写测试方法testUpdateCollege()
 @Test
    public void testUpdateCollege() {
   
        CollgeService service = new CollegeServiceImpl();
        College college = service.findCollegeById(1);
        college.setPresident("王洪礼");
        college.setTelephone("0830-3150380");
        int count = service.updateCollege(college);
        if (count > 0) {
   
            System.out.println("恭喜,学校记录更新成功!");
            college = service.findCollegeById(1);
            System.out.println(college);
        } else {
   
            System.out.println("遗憾,学校记录更新失败!");
        }
    }

运行结果,如下:
在这里插入图片描述
在Navicat中查看:
在这里插入图片描述

2.创建状态服务接口实现类

package net.zhj.student.service.impl;

import net.zhj.student.bean.Status;
import net.zhj.student.dao.StatusDao;
import net.zhj.student.dao.impl.StatusDaoImpl;
import net.zhj.student.service.StatusService;

/**
 * 功能:状态服务接口实现类
 * 作者:朱虹菊
 * 日期:2020年07月08日
 */
public class StatusServiceImpl implements StatusService {
   
    private StatusDao statusDao = new StatusDaoImpl();

    @Override
    public Status findStatusById(int id) {
   
        return statusDao.findById(id);
    }

    @Override
    public int updateStatus(Status status) {
   
        return statusDao.update(status);
    }
}

对StatusServiceImpl进行单元测试

2.1 编写测试方法testFindStatusById()
package net.zhj.student.test;

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

/**
 * 功能:测试状态服务接口实现类
 * 作者:朱虹菊
 * 日期:2020年07月08日
 */
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.
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值