java开发简单的用户管理系统 (2)

还有一个主菜单,用于显示登录界面的

import com.mainmenuitem.Exit; import com.mainmenuitem.LoginItem; import com.mainmenuitem.RegItem; import com.nensoft.bean.Item; import com.nensoft.bean.Menu; import com.utils.ConsoleUtil; public class MainMenu implements Menu{ public void showInfro() { // TODO Auto-generated method stub System.out.println("欢迎使用neusoft用户管理系统"); System.out.println("==================="); 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 LoginItem(); break; case 2: item =new RegItem(); break; case 3: item=new Exit(); } return item; } }

另外一个是管理员的查询菜单

import com.adminmenuitem.ReturnMenu; import com.adminmenuitem.SerchUser; import com.mainmenuitem.Exit; import com.mainmenuitem.LoginItem; import com.mainmenuitem.RegItem; import com.nensoft.bean.Item; import com.nensoft.bean.Menu; import com.serchuser_item.SerchAllUser; import com.serchuser_item.SerchOneUser; import com.utils.ConsoleUtil; public class SerchUserMenu implements Menu{ public void showInfro() { // TODO Auto-generated method stub System.out.println("============"); 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 SerchAllUser(); break; case 2: item =new SerchOneUser(); break; case 3: item=new ReturnMenu(); } return item; } } 有一个工具类,包括数据库的连接,以及对用户输入数据的检测是否规范,com.util包 package com.utils; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.text.Format; import java.util.Properties; public class DBUtil2 { private static DBUtil2 db; private String url; private String username; private String password; private String driver; private DBUtil2(){ Properties properties=new Properties(); try { properties.load(this.getClass().getClassLoader().getResourceAsStream("db.properties")); driver=properties.getProperty("driver"); url=properties.getProperty("url"); username=properties.getProperty("username"); password=properties.getProperty("password"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static DBUtil2 getInstance(){ if(db==null){ db = new DBUtil2(); } return db; } public Connection getConnect() { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Connection conn=null; try { conn = DriverManager.getConnection(url,username,password); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; } public void close(Connection item){ if(item!=null){ try { item.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void close(ResultSet item){ if(item!=null){ try { item.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void close(PreparedStatement item){ if(item!=null){ try { item.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgjspz.html