Java library management system, old programmers spent a day and a night
Popular column recommendation
[1] Java games (Tetris, aircraft war, plant war, zombie, etc.)
[2] JavaWeb project practice (library management, online examination, dormitory management, etc.)
[3] Wonderful examples of JavaScript (aircraft war, snake, verification code, etc.)
[4] Introduction to Java Xiaobai 200 cases
[5] Learn Java from scratch and be interested in learning Java
[6] Idea from zero to mastery
One system interface diagram
introduction:
A few days ago, the little friends in the group said they wanted to build a web library management system (using the most basic syntax of Java: jsp+servlet), so someone said that whoever still does that thing is outdated. I just want to say: never mind that it is not outdated. Many basic things are the most suitable for many fellow students and little friends with poor Java foundation to learn a wave, It's really fragrant, so I wrote this small management system all night, and I'll play it!
Difficulty coefficient (easy entry)
Because there is a relatively basic syntax, it is also relatively easy for Java beginners and small partners who are not very good at the foundation
Back end:
1. Using Java Servlet itself is Java syntax, seamless link and invalid configuration, web XML can be easily configured once.
2. C3P0 is used to connect the database. The configuration file, code and jar package are in place without secondary operation.
3. The code adopts Service and Dao layered logic, which is clear and practical, and the code is simple and easy to understand.
front end:
1.Jsp is also a Java syntax. There is no need to learn new things and write java code directly.
2.HTML only needs the simplest syntax of common tags, and Xiaobai can easily understand it.
3.css is just a little bit of page style, which is easy.
4.JavaScript needs to understand the basic syntax and is necessary for learning web.
5.Jquery is a JavaScript plug-in library, which is only used to interact with the background and only uses $ post can interact with the background.
The most important thing is to let you know how to develop a web system with Java through relatively simple and basic syntax, and fully understand the whole development process, so as to improve your confidence in learning and increase your sense of achievement.
development environment
It's just what I like to use. I can also choose what I like
Development tool: eclipse/myEclipse
Database: mysql
web container: tomcat
jdk version: 1.6
system function
Role introduction
1. Super administrator
Permission: Super administrator is the role with the greatest permission and has all the permissions of the system.
2. System administrator
Management module: login / password management, student management module.
3. Teacher / student
Authority: the role with the least authority only has to modify the password, register, log in and out of the system, query book information and query your own borrowing information.
Table structure introduction
User table
CREATE TABLE `user` ( `id` int(11) NOT NULL auto_increment COMMENT 'Primary key', `no` varchar(20) default NULL COMMENT 'account number-Students usually use student number', `name` varchar(100) not NULL COMMENT 'name', `password` varchar(20) not NULL COMMENT 'password', `sex` varchar(20) default NULL COMMENT 'Gender', `phone` varchar(20) default NULL COMMENT 'Telephone', `role_id` int(11) default NULL COMMENT 'Role: 0 super administrator, 1 administrator, 2 teacher, 3 student', `isValid` varchar(4) default 'Y' COMMENT 'Whether it is effective, Y Valid, others invalid', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Insert super administrator data by default
INSERT INTO `user` VALUES ('1', 'sa', 'Super management', '321', '1', '111', '0', 'Y');
Menu table
CREATE TABLE `menu` ( `id` int(11) NOT NULL, `menuCode` varchar(8) default NULL COMMENT 'Menu coding', `menuName` varchar(16) default NULL COMMENT 'Menu name', `menuLevel` varchar(2) default NULL COMMENT 'Menu level', `menuParentCode` varchar(8) default NULL COMMENT 'Parent of menu code', `menuClick` varchar(16) default NULL COMMENT 'Click triggered function', `menuRight` varchar(8) default NULL COMMENT 'Permission 3 refers to students, 2 refers to teachers, 1 refers to administrators, and 0 refers to super administrators, which can be combined with commas', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Default inserted data (it is recommended to insert line by line. Anyway, my mysql will do it one by one, otherwise the following Chinese will be garbled)
NSERT INTO `menu` VALUES ('1', '001', 'Administrator management', '1', null, 'adminManage', '0'); INSERT INTO `menu` VALUES ('2', '002', 'teacher/Student management', '1', null, 'userManage', '0,1'); INSERT INTO `menu` VALUES ('3', '003', 'Classified management', '1', null, 'categoryManage', '0,1'); INSERT INTO `menu` VALUES ('4', '004', 'Library management', '1', null, 'booksManage', '0,1,2,3'); INSERT INTO `menu` VALUES ('5', '005', 'Borrowing information management', '1', null, 'recordManage', '0,1,2,3'); INSERT INTO `menu` VALUES ('6', '006', 'Change Password', '1', null, 'modPwd', '0,1,2,3'); INSERT INTO `menu` VALUES ('7', '007', 'Exit the system', '1', null, 'logout', '0,1,2,3');
Classification information table
CREATE TABLE `category` ( `id` int(11) NOT NULL auto_increment COMMENT 'Primary key', `name` varchar(100) not NULL COMMENT 'Category name', `remark` varchar(1000) default NULL COMMENT 'remarks', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Book list
CREATE TABLE `books` ( `id` int(11) NOT NULL auto_increment COMMENT 'Primary key', `name` varchar(100) not NULL COMMENT 'title', `category` int(11) not NULL COMMENT 'classification', `count` int(11) default NULL COMMENT 'quantity', `curCount` int(11) default NULL COMMENT 'Quantity on hand', `remark` varchar(1000) default NULL COMMENT 'remarks', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Borrowing information form
CREATE TABLE `record` ( `id` int(11) NOT NULL auto_increment COMMENT 'Primary key', `book` int(11) not NULL COMMENT 'book id', `userId` int(11) not NULL COMMENT 'Borrower', `start_date` date default NULL COMMENT 'Start date', `end_date` date default NULL COMMENT 'End date', `return_date` date default NULL COMMENT 'Return date ', `state` int(1) not NULL COMMENT 'Status: 1 borrow 2 return 3 renew', `admin_id` int(11) default NULL COMMENT 'Operator id', `remark` varchar(1000) default NULL COMMENT 'remarks', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
System module introduction
System administrator management
Only the super administrator has the permission to add, modify and delete system administrators.
Teacher / student management
Both the administrator and the supervisor can operate, such as adding, modifying and deleting.
1. The default status of administrator and override is active.
2. The registration application of teachers and students needs to be activated by the administrator (that is, the account review function).
Classified management
Both the administrator and the supervisor can operate, such as adding, modifying and deleting.
Library management
Administrators and super managers can operate, such as adding, modifying, deleting, borrowing and so on.
Students / teachers only have the function of viewing books
Borrowing operation is carried out in this interface. Select a book to borrow
1. The borrower needs to select
2. The default quantity is 1
3. Return date needs to be selected
Select borrower interface
Borrowing information management
Both the administrator and the supervisor can operate, such as return and renewal.
Students / teachers can only view their borrowing information
Renewal and return can only be operated by the administrator
Registration function
Change Password
Code directory
java file
page
Backend Tiering
Code selection
Borrowing information query
public Map queryByPage(RecordVO vo, int start, int pageSize) { String status="-1"; String content=""; Map retMap = new HashMap(); try { String sqlStrCount = "select count(1) from Record a,books b,user c where 1=1 and a.book=b.id and c.id=a.userId "; String sqlStr = "select a.*,b.name bookName,c.name userName," + " (select name from user c where c.id=a.admin_id) admin_name from Record a,books b,user c where 1=1 and a.book=b.id and c.id=a.userId "; String bookName = vo.getBookName(); if(!"".equals(bookName)){ sqlStrCount +=" and b.name like'%"+bookName+"%'"; sqlStr +=" and b.name like'%"+bookName+"%'"; } String userName = vo.getUserName(); if(!"".equals(userName)){ sqlStrCount +=" and c.name like'%"+userName+"%'"; sqlStr +=" and c.name like'%"+userName+"%'"; } Timestamp date =vo.getStart_date(); if(date!=null){ sqlStrCount +=" and a.start_date='"+date+"'"; sqlStr +=" and a.start_date='"+date+"'"; } String userId = StringHelper.convertStringNull(vo.getUserId()); if(!"".equals(userId)){ sqlStrCount +=" and a.userid='"+userId+"'"; sqlStr +=" and a.userid='"+userId+"'"; } sqlStr +="order by a.id limit "+start+", "+pageSize ; ps = this.getWrappedConnection().prepareStatement(sqlStrCount); rs = ps.executeQuery(); int totalCount=0; if (rs.next()) { totalCount = rs.getInt(1); } retMap.put("totalCount", String.valueOf(totalCount)); rs=null; ps = this.getWrappedConnection().prepareStatement(sqlStr); rs = ps.executeQuery(); List list = new ArrayList(); RecordVO recordVO = null; while (rs.next()) { recordVO = new RecordVO(); recordVO.setId(rs.getString("id")); recordVO.setBook(rs.getString("book")); recordVO.setBookName(rs.getString("bookName")); recordVO.setUserId(rs.getString("userId")); recordVO.setUserName(rs.getString("userName")); recordVO.setStart_date(rs.getTimestamp("start_date")); recordVO.setEnd_date(rs.getTimestamp("end_date")); recordVO.setReturn_date(rs.getTimestamp("return_date")); recordVO.setState(rs.getString("state")); recordVO.setAdmin_id(rs.getString("admin_id")); recordVO.setAdmin_name(rs.getString("admin_name")); recordVO.setRemark(rs.getString("remark")); list.add(recordVO); } retMap.put("list", list); status="1"; } catch (Exception e) { e.printStackTrace(); }finally{ try { this.cleanUp(); } catch (Exception e) { e.printStackTrace(); } } retMap.put("status", status); retMap.put("content", content); return retMap; }
Borrowing record addition
public Map add(RecordVO recordVO) { String status="-1"; String content=""; String id=""; Map retMap = new HashMap(); try { String sqlStr = "insert into Record(book,userId,start_date,end_date,state,admin_id,remark) values (?,?,?,?,?,?,?)"; ps = this.getWrappedConnection().prepareStatement(sqlStr,Statement.RETURN_GENERATED_KEYS); ps.setString(1, recordVO.getBook()); ps.setString(2, recordVO.getUserId()); ps.setTimestamp(3, recordVO.getStart_date()); ps.setTimestamp(4, recordVO.getEnd_date()); ps.setString(5, recordVO.getState()); ps.setString(6, recordVO.getAdmin_id()); ps.setString(7, recordVO.getRemark()); int state = ps.executeUpdate(); ResultSet generatedKeys = ps.getGeneratedKeys(); if (generatedKeys.next()) { id=String.valueOf(generatedKeys.getInt(1));//Primary key } if(state>0){ status="1"; } } catch (Exception e) { e.printStackTrace(); }finally{ try { this.cleanUp(); } catch (Exception e) { e.printStackTrace(); } } retMap.put("status", status); retMap.put("content", content); retMap.put("id", id); return retMap; }
summary
Because of the accumulation of similar systems before, the coding efficiency is relatively high. This is also the ability of old programmers. Those who have code reference CV are very fast, ha ha! I also hope to bring some help to my friends!
Attention
1. The style is relatively simple and may not be very good-looking, because I didn't spend energy on making the style.
2. The watch design may not be particularly perfect and the function is relatively simple. I can't remember it after leaving school for too long.
3. It is inevitable that there will be some bug s, but they are not used online. I think it is enough to refer to learning.
4. There will be a deployment document in the code, and partners can try how to deploy.
**Seeing the big guys here, it's better to use the small hands of making a fortune to point out praise + reply + collection. It's better to pay attention to one wave.
Code acquisition method:
Subscribe to my column< Java Web project practice >After, you can contact the blogger to get all the articles in the column and 1-2 favorite codes. The articles in the column have been on the csdn hot list and are trustworthy! There are currently [6] examples in the column. The column will be updated to more than 15 in the next two months, usually more than once a week, Check out my column. **
Popular column recommendation
[1] Java games (Tetris, aircraft war, plant war, zombie, etc.)
[2] JavaWeb project practice (library management, online examination, dormitory management, etc.)
[3] Wonderful examples of JavaScript (aircraft war, snake, verification code, etc.)
[4] Introduction to Java Xiaobai 200 cases
[5] Learn Java from scratch and be interested in learning Java
[6] Idea from zero to mastery
★ more highlights
? Java tank war, recall childhood!?
? Java Minesweeper game, used to play at school?
? Java student dormitory management system?