今天来看看图书馆管理系统用java web 如何实现!!!!(有点瑕疵,仅供参考)
看看思路,有了逻辑,就能写出来了。
每次写项目之前先把功能,要干啥罗列出来,脑中有那个思路,差不多就能搞出来了!!!!!
先看数据库:::::(订单表就不展示了,后续想要的可以加q):qq:2595471635
用户表 书籍表
代码展示::(一部分)
实体类就不展示了,直接看用户Dao层
//注册 public static int Register(UserTable user,String time) throws Exception { String sql="insert into user_table(user_name,user_box,user_pwd,user_money,user_time) values(?,?,?,?,?)"; Connection connection=getCon(); PreparedStatement statement=connection.prepareStatement(sql); statement.setString(1, user.getUserName()); statement.setString(2, user.getUserBox()); statement.setString(3,user.getUserPwd()); statement.setInt(4, 0); statement.setString(5, time); int result=statement.executeUpdate(); connection.close(); return result; } //看有没有注册过(邮箱) public static int findRegister(UserTable user) throws Exception { String sql="select * from user_table where user_box=?"; Connection connection=getCon(); PreparedStatement statement=connection.prepareStatement(sql); statement.setString(1, user.getUserBox()); ResultSet set=statement.executeQuery(); int a=0; while(set.next()) { a++; } connection.close(); return a; } //登录 public static UserTable login(String box,String pwd) throws Exception { String sql="select * from user_table where user_box=? and user_pwd=?"; Connection connection=getCon(); PreparedStatement statement=connection.prepareStatement(sql); statement.setString(1, box); statement.setString(2, pwd); ResultSet set=statement.executeQuery(); UserTable userTable=null; while (set.next()) { userTable=new UserTable(); userTable.setUserName(set.getString("user_name")); userTable.setUserBox(set.getString("user_box")); userTable.setUserPwd(set.getString("user_pwd")); userTable.setUserMoney(set.getInt("user_money")); userTable.setUserTime(set.getString("user_time")); } connection.close(); return userTable; } //管理员查询所有用户 public static List<UserTable> findAll() throws Exception { String sql="select * from user_table"; Connection connection=getCon(); PreparedStatement statement=connection.prepareStatement(sql); ResultSet set=statement.executeQuery(); List<UserTable> list=new ArrayList<UserTable>(); UserTable user=new UserTable(); while (set.next()) { user.setUserName(set.getString("user_name")); user.setUserBox(set.getString("user_box")); list.add(user); } return list; } //根据邮箱查找 public static int findByBox(String box) throws Exception { String sql="select * from user_table where user_box=?"; Connection connection=getCon(); PreparedStatement statement=connection.prepareStatement(sql); statement.setString(1,box); ResultSet set=statement.executeQuery(); int a=0; while(set.next()) { a++; } connection.close(); return a; } //注销用户 public static int delete(String box) throws Exception { String sql="delete from user_table where user_box=?"; Connection connection=getCon(); PreparedStatement statement=connection.prepareStatement(sql); statement.setString(1, box); int result=statement.executeUpdate(); return result; } //根据邮箱查找 public static UserTable find(String box) throws Exception { String sql="select * from user_table where user_box=?"; Connection connection=getCon(); PreparedStatement statement=connection.prepareStatement(sql); statement.setString(1,box); ResultSet set=statement.executeQuery(); UserTable user=null; while(set.next()) { user=new UserTable(); user.setUserName(set.getString("user_name")); user.setUserBox(set.getString("user_box")); user.setUserPwd(set.getString("user_pwd")); user.setUserMoney(set.getInt("user_money")); user.setUserTime(set.getString("user_time")); } connection.close(); return user; }
接下来是用户的service层
//注册 public static int Register(UserTable user) throws Exception { Date date=new Date(); SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm"); String time=format.format(date); int result=0; int Register=UserDao.findRegister(user); if(Register==0) { result=UserDao.Register(user, time); }else { result=10;//已被注册 } return result; } //登录 public static int login(String box,String pwd) throws Exception { UserTable list=UserDao.login(box, pwd); if(list==null) { System.out.println("没有该用户"); return 0; }else { System.out.println("登陆成功"); return 1; } } //管理员查询所有 public static List<UserTable> findAll() throws Exception { return UserDao.findAll(); } //根据邮箱查找 public static int findByBox(String box) throws Exception { return UserDao.findByBox(box); } //根据邮箱删除 public static int delete(String box) throws Exception { int result= UserDao.delete(box); return result; } public static UserTable find(String box) throws Exception { return UserDao.find(box); }
Servlet层直接调用就ok了。成品就不展示了,想看的直接加qq,2595471635
强调一下,是免费的,不收费,想要的,可以找我,共同探讨。。。。