我的第一个项目----Java图书管理系统

项目参考自:http://www.java1234.com/a/yuanchuang/swing2/
项目视频及代码下载地址:链接:http://pan.baidu.com/s/1pLpQw2J 密码:cncv
项目开发环境的搭建:http://pan.baidu.com/s/1ntzhAmH#list/path=%2F

一,功能

(1),用户登录
(2),图书类别管理
(3),图书管理
(4),退出

二,工具

(1),JAVA编程:eclipes(1.8 soon版本)
(2),SQL:mysql
(3),Jdbc: jar(mysql-connector-java-5.1.40-bin.jar)

三,效果展示

(1),登录

这里写图片描述

(2),主界面

这里写图片描述

(3),图书类别添加

这里写图片描述

(4),图书类别管理

这里写图片描述

(5),图书添加

这里写图片描述

(6),图书管理

这里写图片描述

(7),关于作者

这里写图片描述

四,数据库设计

这里写图片描述

(1),t_user表

这里写图片描述

(2),t_bookType表

这里写图片描述

(3),t_book表

这里写图片描述

(四),Java层次分析:

(1),逻辑图

这里写图片描述

(2),包结构

这里写图片描述

(五),数据库层级分析:

1, ER分析

这里写图片描述

2, 数据

用户: 用户编号,用户名,密码
图书类别:图书类别编号,图书类别名称
图书:图书编号,图书名称,图书作者,图书价格,图书描述,图书类别(外键)

图书类别与图书之间根据图书类别相互关联

3,数据库表的建立
(1),t_use 用户信息表
(2),t_bookType 图书类别管理表
(3),t_book 图书信息管理表

4,数据库表的关联(外键的关联)

这里写图片描述

(六),主要Java代码分析:

(1),Dao 类(以BookDao为例)

package com.java1234.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.java1234.model.Book;
import com.java1234.model.BookType;
import com.java1234.util.StringUtil;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

/**
 * 图书Dao类
 * @author H_Pioneer
 *
 */
public class BookDao {

    /**
     * 图书添加
     * @param con
     * @param book
     * @return
     * @throws Exception
     */
    public int add(Connection con,Book book)throws Exception{
        String sql="insert into t_book values(null,?,?,?,?,?,?)";
        PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);
        pstmt.setString(1, book.getBookName());
        pstmt.setString(2, book.getAuthor());
        pstmt.setString(3, book.getSex());
        pstmt.setFloat(4, book.getPrice());
        pstmt.setInt(5, book.getBookTypeId());
        pstmt.setString(6, book.getBookDesc());
        return pstmt.executeUpdate();
    }

    /**
     * 图书信息查询
     * @param con
     * @param book
     * @return
     * @throws Exception
     */
    public ResultSet list(Connection con,Book book)throws Exception{
        StringBuffer sb=new StringBuffer("select * from t_book b,t_bookType bt where b.bookTypeId=bt.id");
        if(StringUtil.isNotEmpty(book.getBookName())){
            sb.append(" and b.bookName like '%"+book.getBookName()+"%'");
        }
        if(StringUtil.isNotEmpty(book.getAuthor())){
            sb.append(" and b.author like '%"+book.getAuthor()+"%'");
        }
        if(book.getBookTypeId()!=null && book.getBookTypeId()!=-1){
            sb.append(" and b.bookTypeId="+book.getBookTypeId());
        }
        PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sb.toString());
        return pstmt.executeQuery();
    }

    /**
     * 图书信息删除
     * @param con
     * @param id
     * @return
     * @throws SQLException
     */
    public int delete(Connection con,String id)throws Exception{
        String sql="delete from t_book where id=?";
        PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);
        pstmt.setString(1, id);
        return pstmt.executeUpdate();
    }

    /**
     * 图书信息修改
     * @param con
     * @param book
     * @return
     * @throws Exception
     */
    public int update(Connection con,Book book)throws Exception{
        String sql="update t_book set bookName=?,author=?,sex=?,price=?,bookDesc=?,bookTypeId=? where id=?";
        PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);


        pstmt.setString(1, book.getBookName());
        pstmt.setString(2, book.getAuthor());
        pstmt.setString(3, book.getSex());
        pstmt.setFloat(4, book.getPrice());
        pstmt.setString(5, book.getBookDesc());
        pstmt.setInt(6, book.getBookTypeId());
        pstmt.setInt(7, book.getId());
        return pstmt.executeUpdate();
    }

    /**
     * 
     * @param con
     * @param bookTypeId
     * @return
     * @throws Exception
     */
    public boolean existBookByBookTypeId(Connection con,String bookTypeId)throws Exception{
        String sql="select * from t_book where bookTypeId=?";
        PreparedStatement pstmt=(PreparedStatement) con.prepareStatement(sql);
        pstmt.setString(1, bookTypeId);
        ResultSet rs = pstmt.executeQuery();
        String string = new String();
        return rs.next();
    }
}

*重点内容::

JDBC进行简单的数据库增删改查

详细参考:http://www.cnblogs.com/wuyuegb2312/p/3872607.html

(2),Model类(以BookModel为例)

package com.java1234.model;


/**
 * 图书实体类
 * @author H_Pioneer
 *
 */
public class Book {

    private int id; //编号
    private String bookName;  //图书名称
    private String author;  //作者
    private String sex;  //性别
    private float price;  //价格
    private Integer bookTypeId;  //图书类别
    private String bookTypeName;  //图书类别名称
    private String bookDesc;  //备注



    public Book(int id2, String bookName, String author, String sex, float price, Integer bookTypeId, String bookDesc) {
        super();
        this.id = id2;
        this.bookName = bookName;
        this.author = author;
        this.sex = sex;
        this.price = price;
        this.bookTypeId = bookTypeId;
        this.bookDesc = bookDesc;
    }

    public Book(String bookName, String author, Integer bookTypeId) {
        super();
        this.bookName = bookName;
        this.author = author;
        this.bookTypeId = bookTypeId;
    }

    public Book(String bookName, String author, String sex, float price, Integer bookTypeId, String bookDesc) {
        super();
        this.bookName = bookName;
        this.author = author;
        this.sex = sex;
        this.price = price;
        this.bookTypeId = bookTypeId;
        this.bookDesc = bookDesc;
    }

    public Book() {
        super();
        // TODO Auto-generated constructor stub
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getBookName() {
        return bookName;
    }
    public void setBookName(String bookName) {
        this.bookName = bookName;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public float getPrice() {
        return price;
    }
    public void setPrice(float price) {
        this.price = price;
    }
    public Integer getBookTypeId() {
        return bookTypeId;
    }
    public void setBookTypeId(Integer bookTypeId) {
        this.bookTypeId = bookTypeId;
    }
    public String getBookTypeName() {
        return bookTypeName;
    }
    public void setBookTypeName(String bookTypeName) {
        this.bookTypeName = bookTypeName;
    }
    public String getBookDesc() {
        return bookDesc;
    }
    public void setBookDesc(String bookDesc) {
        this.bookDesc = bookDesc;
    }


}

**重点内容::

(1),接口类的构造方法

(2),get,set方法

快捷键:
Shift+Alt+S –> Generate Getters and Setters –>选择你需要的get,set参数

(3),构造函数的使用
快捷键:
(1),Shift+Alt+S –>generate constructor using fields–>使用字段生成
(2),Shift+Alt+S –>generate constructors from…..–>不使用字段从父类获取

(三),Util类

package com.java1234.util;

import java.sql.DriverManager;

import com.mysql.jdbc.Connection;

/**
 * 数据库工具类
 * @author H_Pioneer
 *
 */

public class DbUtil {
    private String dbUrl = "jdbc:mysql://localhost:3306/db_book";
    //也可以写成private String dbUrl = "jdbc:mysql:///db_book";
    private String dbUserName = "root";
    private String dbPassword = "123456";
    private String jdbcName = "com.mysql.jdbc.Driver";

    /**
     * 获取数据库连接
     * @return
     * @throws Exception
     */
    public Connection getCon()throws Exception{
        Class.forName(jdbcName);
        Connection con = (Connection) DriverManager.getConnection(dbUrl,dbUserName,dbPassword);//链接数据库
        return con;

    }

    /**
     * 关闭数据库连接
     * @param con
     * @throws Exception
     */
    public void closeCon (java.sql.Connection con)throws Exception {
        if(con!=null){
            con.close();
        }
    }

    /**
     * 
     * @param args
     */
    public static void main(String[] args) {
        DbUtil dbUtil = new DbUtil();
        try {
            dbUtil.getCon();
            System.out.println("数据库连接成功");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();    //在命令行打印异常信息在程序中出错的位置及原因。
            System.out.println("数据库连接");
        }

    }


}

数据库工具类

package com.java1234.util;

import org.junit.Test;

import com.mysql.jdbc.StringUtils;

/**
 * 字符串工具类
 * @author H_Pioneer
 *
 */
public class StringUtil {
    /**
     * 判断是否为空
     * @param str
     * @return
     */

    public static boolean isEmpty(String str){
        if(str==null||"".equals(str.trim())){
            return true;
    }else{
        return false;
    }
    }

    /**
     * 判断不为空
     * @param str
     * @return
     */
    public static boolean isNotEmpty(String str){
        if(str!=null&&!"".equals(str.trim())){
            return true;
        }else{
        return false;
        }
    }
}

**重点::
工具类的使用
(1)
字符串工具类的总结:
http://www.cnblogs.com/DreamDrive/p/5760588.html
(2)
数据库工具类的总结:
http://kettas.iteye.com/blog/1222519

(四),Frm类(以登录和图书类别添加为例)

package com.java1234.view;

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

import com.java1234.dao.UserDao;
import com.java1234.model.User;
import com.java1234.util.DbUtil;
import com.java1234.util.StringUtil;
import com.mysql.jdbc.Connection;


public class LogOnFrm extends JFrame {

    private JPanel contentPane;
    private final JTextField textField = new JTextField();
    private JPasswordField passwordTxt;

    private DbUtil dbUtil = new DbUtil();
    private UserDao userDao = new UserDao();
    private JTextField userNameTxt;


    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    LogOnFrm frame = new LogOnFrm();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public LogOnFrm() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setAlwaysOnTop(true);
        setTitle("管理员登录");
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);

        JLabel label = new JLabel("图书管理系统");
        label.setFont(new Font("黑体", Font.BOLD, 25));
        label.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/logo.png")));

        JLabel lblNewLabel = new JLabel("用户名:");
        lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 13));
        lblNewLabel.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/userName.png")));

        JLabel lblNewLabel_1 = new JLabel("密  码:");
        lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 13));
        lblNewLabel_1.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/password.png")));
        textField.setColumns(10);

        passwordTxt = new JPasswordField();

        JButton btnNewButton = new JButton("登录");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                loginActionPerformed(e);    
            }
        });
        btnNewButton.setFont(new Font("宋体", Font.PLAIN, 13));

        btnNewButton.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/login.png")));

        JButton btnNewButton_1 = new JButton("重置");
        btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 13));
        btnNewButton_1.setIcon(new ImageIcon(LogOnFrm.class.getResource("/images/reset.png")));
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                resetValueActionPerformed(e);
            }
        });

        userNameTxt = new JTextField();
        userNameTxt.setColumns(10);
        GroupLayout gl_contentPane = new GroupLayout(contentPane);
        gl_contentPane.setHorizontalGroup(
            gl_contentPane.createParallelGroup(Alignment.LEADING)
                .addGroup(gl_contentPane.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
                        .addGroup(gl_contentPane.createSequentialGroup()
                            .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
                                .addGroup(gl_contentPane.createSequentialGroup()
                                    .addComponent(textField, GroupLayout.PREFERRED_SIZE, 0, GroupLayout.PREFERRED_SIZE)
                                    .addGap(223))
                                .addGroup(gl_contentPane.createSequentialGroup()
                                    .addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
                                        .addComponent(lblNewLabel_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(btnNewButton, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                    .addGap(50))
                                .addGroup(gl_contentPane.createSequentialGroup()
                                    .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 93, GroupLayout.PREFERRED_SIZE)
                                    .addGap(36)))
                            .addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
                                .addComponent(btnNewButton_1)
                                .addGroup(Alignment.LEADING, gl_contentPane.createParallelGroup(Alignment.TRAILING, false)
                                    .addComponent(passwordTxt, Alignment.LEADING)
                                    .addComponent(userNameTxt, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)))
                            .addGap(63))
                        .addGroup(gl_contentPane.createSequentialGroup()
                            .addComponent(label, GroupLayout.PREFERRED_SIZE, 320, GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())))
        );
        gl_contentPane.setVerticalGroup(
            gl_contentPane.createParallelGroup(Alignment.LEADING)
                .addGroup(gl_contentPane.createSequentialGroup()
                    .addGap(18)
                    .addComponent(label)
                    .addPreferredGap(ComponentPlacement.UNRELATED)
                    .addComponent(textField, GroupLayout.PREFERRED_SIZE, 0, GroupLayout.PREFERRED_SIZE)
                    .addGap(14)
                    .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                        .addComponent(lblNewLabel, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
                        .addComponent(userNameTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addGap(45)
                    .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                        .addComponent(passwordTxt, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblNewLabel_1, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE))
                    .addGap(27)
                    .addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
                        .addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnNewButton))
                    .addContainerGap(13, Short.MAX_VALUE))
        );
        contentPane.setLayout(gl_contentPane);

        //设置居中显示
        this.setLocationRelativeTo(null);
    }

    /**
     * 登录事件处理
     * @param e
     */
    protected void loginActionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        String userName = this.userNameTxt.getText();
        String password = new String(this.passwordTxt.getPassword());
        if(StringUtil.isEmpty(userName)){
            JOptionPane.showMessageDialog(null,"用户名不能为空");
            return;
        }
        if(StringUtil.isEmpty(password)){
            JOptionPane.showMessageDialog(null,"密码不能为空");
            return;
        }
        User user = new User(userName,password);
        Connection con = null;
        try{
            con = dbUtil.getCon();
            User currentUser=userDao.login(con, user);
            if(currentUser!=null){
                //JOptionPane.showMessageDialog(null,"登录成功");   
                dispose();
                new MainFrm().setVisible(true);
            }else{
                JOptionPane.showMessageDialog(null,"用户名密码错误");
            }

        }catch(Exception e1){
            e1.printStackTrace();

        }

    }

    /**
     * 重置事件处理
     * @param evt
     */

    private void resetValueActionPerformed(ActionEvent evt) {
        // TODO Auto-generated method stub
        this.userNameTxt.setText("");
        this.passwordTxt.setText("");
    }
}

**重点::

(1),Java可视化编程

  1. windowbuilder插件的安装
  2. Window Builder→SWT Designer→SWT→Application Window→Next→窗口名→默认→Finish→s自动生成代码→Design

这里写图片描述

(2),对于按钮等添加事件如何与数据接口联系

对于JFrame,JLable,JTable等,右击可以选择重命名或者添加事件即可返回代码之中,一般我们会把操作进行封装,对事件进行相应的处理

(七),整个项目的分析与不足

1.MVC3层架构有问题(这个只有dao层)

正常的应该是dao层就接口不是实现类,现在的dao是正常的daoImpl,dao的实现类

2.实体类(com.java1234.model包下的)可以是entity,domain

应该尽量用entity或model,少用domain

3 DbUtil和StringUtil的实现方法不好而且很多并没有实际用处

转载于:https://www.cnblogs.com/H---/p/8835672.html

图书资料管理信息系统,带源代码数据库sql文件、课设报告,具备如下基本功能: 1、 系统管理功能有:角色管理、用户管理、修改密码。主要实现系统的安全管理,不同的操作者有不同的权限,可以执行不同的操作。普通读者的权限只能是查询图书及自己的借阅情况;而图书馆管理员可以对图书信息进行管理,如对新书入库,也可以管理用户,如添加新用户和删除不用的账号等。 2、 进书管理功能有:登记基本的图书信息。这部分的功能用于登记新书的书名、作者、出版社、价格、进书的册数、进书日期、ISBN等。 3、 图书入库管理功能有:对新书分类编目,及时更新图书库中的图书信息。这部分的功能用于对所购进的新书,按其种类学科进行编目,给与唯一的书号;及时更新书库中的图书信息,包括书名、书号、作者、出版社、价格、库存位置和库存册数这些信息,方便读者查询借阅。 4、 查询功能功能有:查询图书的信息,查询读者的借阅情况。这部分的功能主要提供多种方式的查询服务。读者可以根据书名、作者或关键字模糊查询图书信息;读者也可以根据自己的借书证号查询自己的借阅情况,如已借了几本书,借书日期,还书日期,有没有续借等。 5、 借书/还书管理功能有:借书管理、还书管理。这部分的功能是当读者借书时,系统根据借书证号识别读者身份,核对读者的借书信息,做出判断如可不可以借、还可借几本,成功借阅后记录在借书信息并修改书库图书信息。当读者还书时,系统根据借书证号识别读者身份,核对读者的借书信息,做出判断如有没有超期,要不要罚款,需要罚多少等,最后还书成功,修改书库图书信息。
本系统主要实现对图书馆图书借阅信息的管理,主要管理读者信息、图书信息、借阅与归还信息、系统用户的信息。 (1)读者信息管理:能够对读者的基本信息进行管理,包括新增读者,如学校新来一名教师,想要借书,就必须先添加读者信息;读者信息的修改,如学生转到别的专业,此时要修改学生的基本信息;删除读者的信息,比如某个学生中途退学了,可以将其信息删除。查询读者的信息,比如有同学拾到了一张借阅卡,卡上有学生的编号,通过此号来查询学生的联系电话,从而可以找到学生。 (2)图书信息管理:能够对图书的基本信息进行管理,包括新增图书,学校每年会购进新书,此时需要将新书的信息录入系统中;图书信息的修改,如学生借书后将图书丢失,此时需要修改图书的总数量,使总数减1;删除图书,学校在购进新书的同时,每年会对过期的图书进行清理,不再提供借阅,此时就需要将这些图书的信息从系统中删除。查询图书的信息,比如要查看有哪些是Java相关的书籍或者指定ISBN号的图书等。 (3)图书借阅信息管理:能够对图书的借阅信息进行记录,包括读者信息、图书信息、借阅时间等信息。 (4)图书归还信息管理:能够对图书的借阅信息进行记录,包括读者信息、图书信息、归还时间、是否超期、罚金等信息。 (5)系统用户信息管理:能够对系统用户的信息进行管理,包括增加新的系统操作用户,对当前系统用户的密码进行修改,以及删除某一用户。 --------------------- 作者:forever_kirito 来源:CSDN 原文:https://blog.csdn.net/forever_kirito/article/details/79111987 版权声明:本文为博主原创文章,转载请附上博文链接!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值