学习完java基础后,自己练了练用MySql作为数据存储的简单用户管理系统,这是一个没有界面的管理系统,看起来比较枯燥,先给出几张截图吧。
首先预览一下包结构吧
第一个是菜单接口,抽象了两个抽象方法,
package com.nensoft.bean; public interface Menu { //显示菜单 void showInfro(); //提供选项(对象) Item pickItem(); }第二个是,菜单项接口,抽象的是菜单执行的方法
public interface Item { //执行功能 Menu excute(); }UserInfo是用来记录当前用户信息的
package com.nensoft.bean; //实体类entity public class Userinfo { private int id; private String username; private String password; private String email; private int power; //无参构造器与框架有关 public Userinfo(){ } public Userinfo(int id, String username, String password, String email, int power) { super(); this.id = id; this.username = username; this.password = password; this.email = email; this.power = power; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public int getPower() { return power; } public void setPower(int power) { this.power = power; } } com.Menu包权限分为普通用户菜单(NormalMenu)和管理员菜单(AdminMenu)
import com.adminmenuitem.AddUser; import com.adminmenuitem.DeleteUser; import com.adminmenuitem.ModifyUser; import com.adminmenuitem.SerchUser; import com.mainmenuitem.Exit; import com.nensoft.bean.Item; import com.nensoft.bean.Menu; import com.nensoft.start.Start; import com.normalmenu.ModifySelfInfo; import com.normalmenu.SerchSelfInfo; import com.utils.ConsoleUtil; public class AdminMenu implements Menu{ public void showInfro() { // TODO Auto-generated method stub System.out.println("=============="); System.out.println("欢迎登录主窗体!"); System.out.println(Start.loginuser.getUsername()+" 您好! "+"您的权限是:管理员"); System.out.println("添加用户---------1"); System.out.println("删除用户---------2"); System.out.println("修改用户---------3"); System.out.println("查询用户---------4"); System.out.println("退出程序---------5"); } public Item pickItem() { // TODO Auto-generated method stub Item item=null; int option=ConsoleUtil.getOption(1, 5); switch(option){ case 1: item=new AddUser(); break; case 2: item=new DeleteUser(); break; case 3: item=new ModifyUser(); break; case 4: item=new SerchUser(); break; case 5: item=new Exit(); break; } return item; } } import com.mainmenuitem.Exit; import com.nensoft.bean.Item; import com.nensoft.bean.Menu; import com.nensoft.start.Start; import com.normalmenu.ModifySelfInfo; import com.normalmenu.SerchSelfInfo; import com.utils.ConsoleUtil; public class NormalMenu implements Menu{ public void showInfro() { // TODO Auto-generated method stub System.out.println("=============="); System.out.println("欢迎登录主窗体!"); System.out.println(Start.loginuser.getUsername()+" 您好! "+"您的权限是:普通用户"); System.out.println("修改自己的信息---------1"); System.out.println("查询自己的信息---------2"); System.out.println("退出程序--------------3"); } public Item pickItem() { // TODO Auto-generated method stub Item item=null; int option=ConsoleUtil.getOption(1, 3); switch(option){ case 1: item=new ModifySelfInfo(); break; case 2: item=new SerchSelfInfo(); break; case 3: item=new Exit(); } return item; } }