一般在接口的实现类中不用来实现登陆等功能,在测试类中实现并且测试。

 1 package com.beiwo.epet.service.impl;
 2 
 3 import com.beiwo.epet.dao.MasterDao;
 4 import com.beiwo.epet.dao.impl.MasterDaoMySqlImpl;
 5 import com.beiwo.epet.entity.Master;
 6 import com.beiwo.epet.service.MasterService;
 7 
 8 public class MasterServiceImpl2 implements MasterService {
 9     @Override
10     public boolean login(Master master) {
11         boolean isLogin = false;
12 
13         MasterDao masterDao = new MasterDaoMySqlImpl();
14 
15         Master master2 = masterDao.findMaster(master);
16 
17         if (null != master2) {
18             isLogin = true;
19         }
20 
21         return isLogin;
22     }
23 
24     @Override
25     public void login() {
26 
27     }
28 
29 }

 

测试类

 1 package com.beiwo.epet.test;
 2 
 3 import java.util.Scanner;
 4 
 5 import org.junit.Test;
 6 
 7 import com.beiwo.epet.entity.Master;
 8 import com.beiwo.epet.service.MasterService;
 9 import com.beiwo.epet.service.impl.MasterServiceImpl;
10 import com.beiwo.epet.service.impl.MasterServiceImpl2;
11 
12 public class TestMasterDao {
13 
14     @Test
15     public void testLogin(){
16         MasterService masterService=new MasterServiceImpl();
17         masterService.login();
18         
19     }
20     
21     @Test
22     public void testLogin2(){
23         Scanner scanner = new Scanner(System.in);
24 
25         // 1.输入用户名
26         System.out.println("请输入用户名");
27         String loginId = scanner.next();
28 
29         // 2.输入密码
30         System.out.println("请输入密码");
31         String password = scanner.next();
32         
33         MasterService masterService=new MasterServiceImpl2();
34         Master master=new Master();
35         master.setLoginId(loginId);
36         master.setPassword(password);
37         
38         boolean isLogin=masterService.login(master);
39         
40         if(isLogin){
41             System.out.println("登陸成功");
42         }else{
43             System.out.println("登陸失敗");
44         }
45         
46         
47     }
48     
49     
50 }

 

posted on 2016-12-14 10:23  栗子先生i  阅读(325)  评论(0编辑  收藏  举报