ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java web图书馆管理系统

2022-06-11 21:32:29  阅读:139  来源: 互联网

标签:box web set java String 管理系统 connection user statement


今天来看看图书馆管理系统用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

强调一下,是免费的,不收费,想要的,可以找我,共同探讨。。。。

  

  

标签:box,web,set,java,String,管理系统,connection,user,statement
来源: https://www.cnblogs.com/silasiladi/p/16366842.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有