黑猴子的家:Stock(十 三) 创建 UserView 类

1、view 包下 –> New –> Class

13909371-e8877eaeae743609.png

2、Name -> UserView -> Finish

13909371-6515038bff926c8f.png

3、UserView 类 内容

package com.yg.view;

import java.util.List;
import java.util.Scanner;
import com.yg.entity.User;
import com.yg.service.UserService;
import com.yg.serviceimpl.UserServiceImpl;

public class UserView {

      User user = null;
      UserService userService = new UserServiceImpl();

      public User login(Scanner sc) {
            System.out.println("请输入用户名");
            String userNo = sc.next();
            System.out.println("请输入密码:");
            String pwd = sc.next();
            user = userService.login(userNo, pwd);
            if (user != null) {
                  System.out.println("登录成功!");
            } else {
                  System.out.println("登录失败!!!");
            }
            return user;
      }

      public void add_User(Scanner sc) {
            System.out.println("输入学号:");
            String userNo = sc.next();
            System.out.println("输入用户名:");
            String userName = sc.next();
            System.out.println("输入密码:");
            String pwd = sc.next();
            User user = new User();
            user.setUserno(userNo);
            user.setUsername(userName);
            user.setPwd(pwd);
            if (userService.add_User(user)) {
                  System.out.println("添加用户成功");
            } else {
                  System.out.println("添加用户失败");
            }
      }

      public void show_User_List() {
            System.out.println("所有用户信息如下:");
            List<User> list = userService.get_All_Users();
            System.out.println("用户ID"
                                + "\t\t用户登录账号"
                                + "\t\t用户姓名"
                                + "\t\t密码"
                                + "\t\t性别"
                                + "\t\t年龄"
                                + "\t\t职位");
            for (User user : list) {
                  System.out.println(user.getId() 
                                    + "\t\t" + user.getUserno() 
                                    + "\t\t" + user.getUsername() 
                                    + "\t\t" + user.getPwd() 
                                    + "\t\t" + user.getSex() 
                                    + "\t\t" + user.getAge() 
                                    + "\t\t" + user.getPosition());
            }
      }

      public void delete_User(Scanner sc) {
            System.out.println("请输入要删除的用户id:");
            String id = sc.next();
            if (userService.delete_User(id)) {
                  System.out.println("删除成功。");
            } else {
                  System.out.println("删除失败!!!");
            }
      }
      
      public void edit_User(Scanner sc) {
            User user = new User();
            System.out.println("请输入要修改的用户id:");
            int id = sc.nextInt();
            System.out.println("请输入要修改的用户username:");
            String username = sc.next();
            System.out.println("请输入要修改的用户userno:");
            String userno = sc.next();
            System.out.println("请输入要修改的用户pwd:");
            String pwd = sc.next();
            user.setId(id);
            user.setUsername(username);
            user.setUserno(userno);
            user.setPwd(pwd);
            if (userService.edit_User(user)) {
                  System.out.println("修改成功。");
            } else {
                  System.out.println("修改失败!!!");
            }
      }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值