User information list management system (dark horse small project)

Keywords: Java

1, Project scenario:

Develop a simple user information list management system, which can be used to add, delete, modify and query user information. The following shows the functional effect diagram of the modified system:

(1) When the server is started, there is an administrator login page. You need to log in successfully before you can enter the user information system:

(2) After logging in successfully, you will enter the query user information interface (index.js)

(3) Click "query all user information" to enter the user information management list to view the user information function.

(4) In the table modification, the following functions are available:

① You can filter out the required user information through conditional query

② You can "add contact" and "delete selected contact" in the system

③ You can modify and delete a single contact in the system

④ Page by page query function to query all information in the system page by page

2, Overall framework process of project development:

The following is a brief introduction to the overall project development process. In the company, we only need to be responsible for the development process.

(1) Demand analysis: add, delete, modify and query user information.
(2) Design:
   1. Technology selection: servlet + jsp + MySQL + jdbc template + Druid + BeanUtils + Tomcat
    2. Design database

(3) Development:

    1. Environmental construction:
       ① create database environment
        ② import the jar package required by the project
    2. Code
(4) Test:
    test and adjust after project development
(5) Deploy O & M:
    deploy the project in the server

3, Development process:

(1) Overall structure of the project

The whole project consists of "src" and "web".

(1) In the src package, we divide it into the following folders according to the three-tier architecture mode of Java and save the corresponding function files.
The following are the subpackages in src:

The following is the three-tier architecture mode in java development: (you can view "Java three-tier architecture" on Baidu to understand its principle

The following describes the functions of the files placed in each package in each project:

  ① dao layer (MyBatis framework) – > defines the most basic CRUD operations for the database, including functions to add, delete, modify and query. You need to enter sql functions to access the database

  ② domain layer – > stores User and PageBean objects, which are used to encapsulate User information

  ③ service layer (Spring Framework) – > call simple methods in the composite dao layer to form complex functions.

  ④ util layer – > the package used to store tool classes, such as JDBC utils tool classes

  ⑤ web layer (spring MVC layer) – > it contains the Servlet file of each function block, which is used to receive user parameters, encapsulate data, call the service layer to complete processing, and then forward it to the jsp page to complete display.

⑥ druid.properties file, which is used to link MySQL database

(2) In the web package, it is used to place the front-end UI presentation page and jsp file

The web contains css, font, js, jar packages and jsp files needed in the front-end UI, and the WEB-INF is used to store jar packages



(2) Environment construction

  (1) create a database environment. The following is a SQL statement to create a database:

create database day17; -- Create database
		use day17; 			   -- Use database
		create table user(   -- Create table
			id int primary key auto_increment,  --user id
			name varchar(20) not null,			--full name
			gender varchar(5),					--Gender
			age int,							--Age
			address varchar(32),				--address
			qq	varchar(20),					--qq
			email varchar(50),					--e-mail address
			username varchar(32),				--Login user name
			password varchar(32)				--Login password
		);

  (2) create the project and import the required jar package. (the source code will be provided later in Web - > WEB-INF - > lib package)

  (3) introduce the JDBC utils file and druid.properties file to link the MySQL database.



(3) Function development

(1) Login function analysis


(1) Write the login page in the login.jsp file, and submit the data (user name, password and verification code) entered in the page to the login servlet in the server web layer through the form form.

<form action="${pageContext.request.contextPath}/loginServlet" method="post">

(2) In loginServlet
   1. Get the parameter map set passed in from login.jsp (the map contains user name and password) and get the input verification code value separately.
  2. Encapsulate User information into User object
   3. Judge whether the verification code generated by the program is consistent with the verification code entered by the user,
     if consistent: further judge whether the user name and login password are consistent (refer to 4 for judging whether the user login is successful).
     if inconsistent: send the error message and forward it back to login.jsp on the login page
  4. Judge whether the user logs in correctly:
    if yes: store the user information in the session and redirect it to the index.js page
    if not: store the login error information and forward it back to login.jsp on the login page

The pseudo code is shown below to illustrate the logic of the login function

/**
*LoginServlet class
*/

1.obtain login.jsp Verification code data transmitted from

2.Get the verification code generated in the program  //The verification code is generated through the CheckCodeServlet and stored in the session

//Judge whether the input verification code is equal to the generated verification code. If it is equal, continue to judge whether the user name is correct. If not, don't want to wait.
//In order to simplify the code, enter the if condition by judging whether the verification code is wrong, and jump out of the function through return. After jumping out of the judgment condition, do not execute the things behind the if. If the verification code is entered correctly, do not execute the things in the if condition and directly execute down.
3.
if(Verification code of program != Verification code entered){
	
	(1).Store login error information to request in

	(2).Forward back to the original landing page login.jsp Continue login in
	
	(3). return;   //After executing return, the function will jump out, and the code behind the if condition will not be executed
}

4.Get the entered user name and password map In collection

5.take map The information in the collection is encapsulated into JavaBean Object user

6.By calling service Layer query user user Does it exist   //The service layer will call the function of dao layer to query data from the database

//Judge after query
7.if(user user existence){
	(1).Store user information in session in
	(2).Then redirect to index.js On page
}else{
	(1).Store login error information in request in
	(2).Forward back to login page login.jsp in

}



(2) Analysis of list query function


Pseudo code analysis:

/**
*UserListServlet class
*/
1.adopt service Layer to obtain user information user		//The service layer obtains database information indirectly through the dao layer

2.Store user information in request in

3.Forward user information to list.jsp Show the page

/**
*list.jsp
*/
1.to write foreach Label loop traversal list Generate data information table from set



(3) Add functional analysis


Pseudo code analysis:

/**
*Write the add.jsp page and draw the whole table
*/
1.Write a simple add information page
2.set up form form  action Submit path to AddUserServlet in

/**
*Write AddUserServlet
*/
1.Get the transmitted data and encapsulate it as an object
2.adopt service Layer indirect call dao Layer to add data to the database
3.Jump userListServlet Query layer data




(4) Delete function analysis


Note:
(1) To delete this record, you need to bind it to the id of this record to obtain its deletion information. This id is very important and needs to be obtained from list.jsp and passed into DelUserServlet.



(5) Modify function analysis


Pseudo code analysis:

/**
*This function needs to be divided into two parts:
*	1.When you click Modify, you will jump to update.jsp, and you need to echo the obtained data in the update.jsp page through findUserServlet.
*	2.After modifying the information in update.jsp, submit the data to UpdateUserServlet, store the information in the database and jump back to userListServlet for display
*/
//Part I code implementation
1.Like the delete function, you need to list.jsp Bind user in id
2.stay findUserServlet Get bound from id Information, and then through the id Retrieve information by querying in the database
3.Will pass Id The obtained user information is encapsulated and forwarded to update.jsp Echo the message in

//The second part is the code implementation
1.from update.jsp Get the submitted form information in and encapsulate it as an object
2.adopt service Layer stores data in the database
3.Redirect back userListServlet Query object in



(6) Delete selected function analysis


Pseudo code analysis:

/**
*In list.jsp
*/
1.Get selected id Array, and then submit to DelSelectedServlet

/**
*In DelSelectedServlet
*/
1.adopt getParameterValue()obtain id array
2.call userService()Delete
3.Forward to query all UserListServlet

/**
*In userServiceImp
*/
public void deleteSelectedUser(String[] uids) {

	1.Traverse each uid,Then call dao Layer existing delected()Function to delete
	for(String id : uid){  // The for each loop statement traverses the array. It is not clear that Baidu can be used. In fact, it is the same as the for loop
		dao.delect(Interger.paraseInt(id))
	}


}



(7) Analysis of paging query function





(8) Analysis of paging function under complex conditions



4, Supplementary notes:

The following (7) paging query function analysis and (8) complex condition paging function analysis are not analyzed in detail. This function is relatively complex. We will supplement this blog later when we have time. Partners in need can go to station B to search for the dark horse video for viewing



5, Code warehouse:

Code cloud: https://gitee.com/bofuser/user-manage-system.git
GitHub: https://github.com/Bofuser/UserManageSystem.git

Posted by gamefreak13 on Sun, 07 Nov 2021 17:00:10 -0800