[java graduation design] Design and implementation of BS architecture microblog system based on javaEE+SSM+MySql (graduation thesis + program source code) - BS architecture microblog system

Design and implementation of BS architecture microblog system based on javaEE+SSM+MySql (graduate thesis + program source code)

Hello everyone, today I will introduce to you the design and implementation of the BS architecture microblog system based on javaEE+SSM+MySql. At the end of the article, the thesis and source code download address of this graduation project are attached. Friends who need to download the PPT template of the opening report and the PPT template of the thesis defense, etc., can enter the homepage of my blog and check the self-service download method in the bottom column on the left.

Article directory:

1. Project introduction

  1. As a platform for information exchange and sharing, Weibo is particularly important in this information age. People can browse and publish information at will to obtain the latest and hottest consultation, and its timeliness and high interaction make it popular among people. With the popularity of Weibo among netizens, microblog effects such as Internet celebrities and Internet hot words have gradually formed. The microblog system adopts B/S architecture to realize the original basic functions of microblog. In the previous Weibo system, we added rewards for questions, adopted points and other new functions to improve user experience, and realized comprehensive management of Weibo and users in the background management. In terms of implementation technology, the page uses JSP, javaScript, ajax and other technologies to improve The interaction between the system page and the user uses the Java language in the background, the Tomcat server is used as the server, the SSM framework is used to realize specific functions, and the Oracle database is used to store data in the database.
  2. The main functions of the microblog system based on the B/S architecture include: user login and logout, user information maintenance, microblog publishing, friends' attention, posting questions, etc. The system structure is as follows:
    (1) User module:
    realize the login function
    , realize the exit of user login
    , realize user registration
    , realize the modification of registered user information
    (2) Weibo module:
    realize the functions of publishing, modifying and viewing Weibo;
    realize Weibo Operating users can view personal Weibo, friend Weibo, favorite Weibo and other information, like, repost, favorite, comment, delete, etc. on Weibo (3) Friends module: realize user attention, number of followers +1, number of
    fans
    + 1. Unfollow, block users, private message search users, etc.;
    (4) Conch module:
    realize posting questions, answering questions, increasing points, etc.
    (5) Background administrator module
    Realize administrator login
    and use bar graph to display Weibo, Statistical results of users, comments, conch, comments, answers, etc.
    User search, user ban
    Weibo search, Weibo deletion
    Conch search, conch deletion

2. Resource details

Project Difficulty: Medium Difficulty Applicable Scenarios: Graduation Design Supporting Papers
on Related Topics Number of Words: 28461 words, 77 pages Contents: Complete set of source code + complete graduation thesis + defense PPT + task book + tutoring video + running screenshots


3. Keywords:

Weibo; B/S architecture; java; SSM framework; Oracle;

4. Brief introduction:

Reminder: The following is a brief introduction to the graduation project, the source code of the project and the download address of the complete graduation thesis are at the end of the article.

Introduction
omitted

And Sina Weibo still continues its own celebrity effect. An ordinary account, without the attention of fans, it is difficult for others to see the Weibo. If you need to ask for help on Weibo, there is no "celebrity big V" It is difficult to be noticed by others. If you want to seek help in Weibo, you need Weibo to provide more services. And this system enables users to reward their own questions by using the point reward function, so that more users can answer their own questions and get more people's help.

Chapter 2 Introduction of related technologies

2.1 Architecture overview
B/S architecture (Browser/Server, browser/server mode): It is a network structure mode that uses the browser as the client, uses the gradually mature web browser technology, and combines the various functions of the browser , use the browser as the complex client under the earlier C/S (Client/Serve) architecture, use the C/S architecture to unify the user's client, concentrate the core functions of the software system on the server, upgrade the system and Maintenance is simpler. Developers only need to manage servers to update and maintain software systems. The many advantages brought by the B/S architecture make it the mainstream direction of future informatization development.

MVC mode: Model (Model), View (View), and Controller (Controller) are a design pattern for software development. Model is mainly responsible for data interaction of separated business logic, View is mainly responsible for data submission and display, and Controller Mainly responsible for obtaining requests and request forwarding.

SSM framework (SpringMVC+Spring+Mybatis): The framework of web projects composed of these three open source frameworks is a standard MVC model. Spring MVC is responsible for request forwarding and view management. Spring implements business object management and transaction control. Mybatis serves as Persistence engine. Compared with the earlier popular SSH (Struts+Spring+Hibernate) framework, SSM, as a lightweight framework, is more suitable for developing small and medium-sized projects.

2.2 Introduction to key technologies
Front-end technology:
1. JSP (Java Server Pages): HTML pages embedded with java codes, essentially a servlet, which implements the extension of java codes in the syntax of htmld, using the <% %> format.

2. JavaScript: It is a weakly typed scripting language, which consists of three parts: ECMAScript describes the basic objects and syntax of JavaScript, Document Object Model (DOM), and Browser Object Model (BOM).

3. Ajax (Asynchronous Javascript And XML): Asynchronous JavaScript and XML, realize asynchronous interaction between the front and back, and partially refresh some content on the page without reloading the entire page.

Background technology:
1.java: An object-oriented programming language, the main features include: (1) Simplicity: Abandoning the complex syntax and multiple inheritance of pointers in C++, developers do not need to pay attention to the underlying optimization, only need to pay attention to Business logic is fine, (2) object-oriented, for programmers, they only need to pay attention to the corresponding data and the method of processing data, and do not need to write code strictly in accordance with the process, because the java language is object-oriented, so it is also It has the three major characteristics of object-oriented, inheritance, encapsulation and polymorphism, (3) cross-platform, the cross-platform of java language is also the cross-platform of JVM (java virtual machine). After the Java file is compiled, it will not directly generate the binary file that the machine directly runs, but compile it into a class file. The JVM will generate the binary file of the corresponding system according to the JVM under different operating systems. It only needs to be compiled once, and the Can run on different platforms.

2. SpringMVC: It is a module provided by the Spring framework, which simplifies Web development by implementing the MVC pattern to separate data, business and presentation. Like other MVC frameworks, it is request-driven and controls forwarding. Its core Servlet is DispatcherServlet, which is the front controller, which is used to distribute requests to the controller. It is fully integrated with the Spring framework. This also makes SpringMVC a very popular MVC framework.

3. Spring: A lightweight java development framework, the Spring framework has a layered architecture, so you can use any independent part of Spring. And its architecture is still inherently stable. Spring provides solutions for each layer of J2EE applications, running through each layer of the three-tier architecture, but Spring is still very compatible with other frameworks. This project mainly uses the IOC in Spring ( Inversion of Control) and AOP (Aspect-Oriented Programming) modules.

4. Mybatis: It is a lightweight open source framework that simplifies the Java persistence layer. And it supports annotation Mapper, Mybatis eliminates most of the JDBC code, making the process of persisting Java objects to the database easier. Compared with other Java persistence frameworks, Mybatis has the advantage of eliminating a lot of JDBC redundancy. The rest of the code, easy to learn, and visible Sql statements provide integration with Spring and introduce better performance.

2.3 Development tool
Tomcat server: it is a web application server, it is lightweight and open source, it is the first choice for small and medium-sized web projects and development, debugging and learning.

Oracle Database (Oracle Database): is a relational database developed by Oracle Corporation. It is the first relational database for commercial applications. The system is easy to use, powerful and highly portable. It is suitable for various large, medium and small environments. In the era of big data, as a distributed database, it realizes the function of distributed processing, with complete data management functions, complete relational databases, and distributed processing functions.

Eclipse development tool: an extensible development platform based on java open source, which includes not only java integrated development environment, but also plug-in development environment, such as SVN, CVS and other teams to develop plug-ins.

2.4 Summary of this chapter
This chapter mainly introduces some of the main technologies used in the development project, the architecture and design patterns used in the project, the main framework technologies used in the project, the front-end technology and display methods used in the project display on the browser side, The development language used by the background code, the server technology used, the database used by the data persistence layer, etc., and the development tools used for development are introduced at the end of this chapter.

Chapter Three System Requirements Analysis

3.1 Feasibility analysis
3.1.1 Technical feasibility
In terms of existing technologies, in order to unify the client and eliminate the complexity caused by version upgrades and maintenance, it is completely feasible to adopt a mature B/S architecture in the realization of the project. In terms of development languages ​​and frameworks, the powerful java and j2ee systems allow developers to carefully build web projects, and a series of open source frameworks provide a strong basis for the feasibility of the project. In terms of servers, the open source server Tomcat is used , is enough to support the normal use of this small project, and the constantly developing front-end technology and front-end framework can make beautiful front-end pages and improve user experience and interaction. This is completely feasible in the project's page display technology. A powerful relational database is The persistence of project data provides a strong backing. To sum up, the increasingly mature java and j2ee systems, fully open source java framework and server, powerful relational database, and the use of web front-end technology to provide user interaction pages, so the project is technically feasible.

3.1.2 Economic feasibility
Omit

3.1.3 Operational Feasibility
Omit

3.2 Requirements Analysis
3.2.1 Overall System Requirements
The Weibo system is mainly composed of the front-end user module and the background management module. When the user enters the home page, he can choose to log in or not. When logging in, he can log in with an existing account or register a new account. When the user is not logged in, the recently updated popular Weibo is displayed on the homepage, and the logged-in user can see the recently updated Weibo of the user he or she follows on the homepage.

Non-logged-in users can only search and view Weibo information and visit user homepages. Logged-in users can modify their basic information such as signature, gender, etc. after logging in to the system, and can also modify passwords and confidential information after verifying user information. As well as modify user avatar and password, edit your own personal homepage, like, comment, bookmark and other functions on Weibo, you can also follow/unfollow users, block users, private chat users and other operations.

The background administrator can view all the data of the system, including users, microblogs, comments, conchs, the total amount of answers, the latest database, and the amount of data in the last week. The specific functions include management of bad Weibo information and bad accounts, deletion and restoration of Weibo, Weibo comments, conch, answers and other information, and blocking of bad accounts.

Microblog search module: users can input keywords to find corresponding microblogs or users.
Micro-blog publishing module: the user clicks posting and adds the content he/she wants to send in the content. You can choose emoticons or insert pictures, but there is a limit to the number of characters entered, and you can also insert a picture at the same time.

Weibo comment module, users can view Weibo comments, post Weibo comments, etc.

Magic Conch Module: Users can publish a magic conch, which is mainly used to record various questions raised by users, and other users can view and answer questions. When the answer of the respondent is adopted by the questioner, the respondent can add his own conch Points, different conch points have different conch titles.

Points module: Users can increase their points by logging in every day, posting Weibo, doing tasks, etc. Different points have different titles. The points of the magic conch module have different titles, and the titles are displayed behind the user's name.

Friend module: users can view other users in the system, find their favorite users and follow them. After following them, they can view the users they follow in the friend module, as well as the recent Weibo and other information released by friends. They can also private message friends, send Send a private message to a friend.

3.2.2 Use Case Diagram Requirements
1. When the user enters the system, he can choose to log in or register as a user. If he forgets the password, he can reset the password through the security question.
insert image description here

Figure 3.1 User initial use case diagram

2. After the user logs in, he can manage the user's basic personal information, modify the user's basic information, and modify the user's confidential information. Modify user avatar and other functions.
insert image description here

Figure 3.2 User Information Management Use Case Diagram

3. User microblog management system, when the user logs into the system, he can publish microblog on the homepage, and search for the microblog information of keywords in the microblog content through keywords. View Weibo, including viewing personal Weibo, friend Weibo, and recommended Weibo.
insert image description here

Figure 3.3 Weibo management use case diagram

4. Comment management, comment management depends on the Weibo module, users can view comments on Weibo, post comments on Weibo information, and delete their own comments.
insert image description here

Figure 3.4 Weibo comment management use case diagram

5. Conch management. After logging in, users can post conch questions in the conch module. When posting questions, they can choose the number of reward points and reduce their own points. Users can participate in answering other people's conch questions. When the answer is accepted, You can get the number of points rewarded by the user.
insert image description here

Figure 3.5 Conch management use case diagram

6. Friends management, when the user logs in, he can follow the system to recommend friends, or search for users, view the user's home page, add or unfollow users, send private messages to users, or block users.
insert image description here

Figure 3.6 Friend management use case diagram

7. Message notification, when the user pays attention, Weibo comments, likes, and favorites, the message notification is called.
insert image description here

Figure 3.7 Friend management use case diagram

8. Administrator: Administrators can manage Weibo users by logging in to the system, banning and canceling accounts for bad users, and can also restore user status. At the same time, administrators can also manage Weibo information, such as deleting Weibo, restoring Delete and recover microblog comments deleted by administrators, etc., as shown in Figure 3.2.
insert image description here

Figure 3.8 Administrator use case diagram

Chapter 4 System Function Design
4.1 System class analysis
4.1.1 Entity classes
Entity classes are mainly used to transfer data, mainly including User, Friend, PointAction, PointRecord, Weibo, WeiboCollect, WeiboComm, WeiboLike, WeiboTrans, etc. User classes include user Basic information, the Weibo category includes the basic information of Weibo and also includes the entity user category, the friend category includes the friend number, the friend creation time and the user category of both parties, etc. The microblog collection class includes collection attributes such as the favorite microblog class and user id, the microblog comment class includes attributes such as microblog class, user class, and comment content, and the microblog forwarding class includes attributes such as user class, microblog class, and forwarding time , the Weibo like category includes attributes such as Weibo category, user category, and like time. The class association relationship between entity classes is shown in Figure 4.1.
insert image description here

Figure 4.1 Bean layer class diagram

4.1.2 The controller class
includes four JAVA classes MainController, WeiboController, FrendController, and AdminController in the controller layer. In the SpringMVC framework, it is mainly used to receive the request sent by the browser to the server and process the data and control the forwarding of the request. The obtained data is responded to the browser. MainController is mainly used to receive form or link requests submitted from user-related pages, and pass the requested parameters to the corresponding method in the Controller, carry the data response to the browser, and display the data, specific attributes and methods on the browser side As shown in Figure 4.2.
insert image description here

Figure 4.2 User controller class diagram

WeiboController is mainly used to receive form or link requests submitted from relevant Weibo pages, pass the requested parameters to the corresponding methods in the Controller, obtain the data returned in the business processing layer, and send the data response to the browser , to display data on the browser side, the specific properties and methods are shown in Figure 4.3.
insert image description here

Figure 4.3 Weibo controller class diagram

FriendController is mainly used to receive form or link requests submitted from friend-related pages, and pass the requested parameters to the corresponding method in the Controller, and obtain the data returned in the business processing layer, and carry the data response to the browser , to display data on the browser side, the specific properties and methods are shown in Figure 4.4.
insert image description here

Figure 4.4 Friend Controller Class Diagram

AdminController is mainly used to receive form or link requests submitted from relevant pages of the administrator, and pass the requested parameters to the corresponding method in the Controller, and obtain the data returned in the business processing layer, and carry the data response to the browser The browser displays data on the browser side. The specific properties and methods are shown in Figure 4.5.
insert image description here

Figure 4.5 Admin Controller Class Diagram

4.1.3 Business logic class
The Service layer mainly includes four Service interfaces and their implementation classes, including IUserService used to handle user business such as user registration, login, and modification of personal information, as shown in Figure 4.6. IWeiboService is used to handle Weibo-related businesses such as searching Weibo, publishing Weibo, deleting Weibo and related operations on Weibo such as likes and comments, as shown in Figure 4.7. IFriendService is used to handle business related to user friends, such as like, cancel like, private message, blacklisting and other functions, as shown in Figure 4.8. IAdmoinService is used to handle business related to administrators, such as administrator login, chart display, user management, Weibo management, and conch management functions, as shown in Figure 4.8.
insert image description here

Figure 4.6 User business processing class diagram

insert image description here

Figure 4.7 Weibo business processing class diagram
insert image description here

Figure 4.8 Weibo controller class diagram

4.1.4 Database interaction class
Since the system adopts the MyBatis persistence framework, developers do not need to pay attention to the specific JDBC code between the database and the database, but only need to process business logic, so they only need to declare methods in the Dao layer interface without writing The implementation class of the interface implements the method by configuring the corresponding configuration file, and writes the SQL statement in the corresponding interface method in the configuration file to interact with the database.

4.2 Key business design
4.2.1 Login system
insert image description here

Figure 4.9 System login sequence diagram

After the user enters the homepage, he can select a registered user on the left, or log in to the system on the right. In the registration module, the user enters the user's email address, password, nickname and other information. When the user enters the email address, the email address entered by the user will be sent to the background through Ajax. Check whether the user's email address has been registered. If it is registered, the user will be prompted on the page that the email address has been registered. After entering the basic information and clicking Register, the user registration information will be saved.

Login function, when the user enters the email address and password, if the user clicks the next automatic login password, after clicking the login, it is judged whether the user's current login time and the last login time are on the same day, if not, add the login time for the user Points, and then jump to the Weibo homepage.

4.2.1 User Information System
insert image description here

Figure 4.10 User modification information sequence diagram

User basic information: After clicking personal account settings on the home page of the system, it will jump to the page of modifying user basic information, where the user can modify these basic information and save the modified information in the database.

Change password: Click Change password on the user profile page, jump to the change password page, the user can enter the user's current password, the system judges whether the password is correct, if the password is incorrect, it will display the face-to-face password error, if the password is correct, the user can Enter a new password and click Modify to update the modified password to the database.

Modify user avatar: Click to modify the avatar in the user profile, jump to the page for modifying the avatar, the user selects the avatar file, clicks upload, and the user avatar is saved on the server. It is judged that the user’s previous avatar is the default avatar of the system, and if not, delete the user For the previous avatar picture, click Modify to save the modified avatar address in the database.

Modify password: the user first needs to fill in the answer according to the previously set security question. If the security answer is wrong, the user will be prompted that the security answer is wrong. If the security answer is correct, the user can enter a new security question and security answer. Click Modify to save the user's new security question and answer.

4.2.2 Weibo module
insert image description here

Figure 4.11 System login sequence diagram

Publish Weibo: Users can publish Weibo on the homepage, insert emoticons in the Weibo information, or choose to insert a picture, when the user clicks publish, the browser sends a request to upload the Weibo information and picture information in the front page form Pass it to the background controller, save the picture information in the server, save only the picture path in the database, and finally save the Weibo information in the database.

Search Weibo: Users can enter the content mentioned in Weibo in the search box on the home page to search, and the system will query related Weibo information in the database through fuzzy queries. Display the searched pages on the page, and display the keywords in red.

Weibo operations: users can view personal Weibo, friend Weibo, favorite Weibo and other information, like, repost, favorite, comment, delete, etc. on Weibo.

4.2.3 Friend module
Follow function: When the user logs in to the system, he can choose the user to follow from the recommended users on the right side of the page, or search for users through the search function on the page, and follow the searched users. After following the user, the personal attention +1, and the number of fans of the followed user +1.

Unfollow: and follow function type, click my friends in the navigation bar, check my friends on the homepage of my friends, you can check all the friends I follow, the number of friends and their personal information, by clicking The corresponding unfollow can unfollow the user. After unfollowing the user, the number of personal followers is -1, and the number of followers of the followed user is -1.

Blocking users: That is to modify the corresponding record status in the friend table, and the private messages and Weibo information published by the blocked users will not be seen by the blocked users.

Private messages: You can view the number of unread private messages of the current logged-in user on the recommended user on the page. The number of unread private messages will pass through the database for all private messages of all recipients of the current logged-in user, and the information status is unread. The obtained value is displayed on the front page.

Send private message: The user first selects the user to send, enters the private message information to be sent, and can insert emoticons in the private message. After clicking send, the private message information will be sent to the corresponding user. At the same time, increase the number of unread private messages that prompt the user.

Search users: On the search user page, users can enter keywords of user nicknames to fuzzily search for relevant users, display the queried users on the page, and mark the keywords entered by users in red.

User homepage: On the page, clicking any user's name or profile picture will jump to the corresponding user's personal homepage. The user's personal homepage displays the user's personal information and the user's latest Weibo, arranged in reverse chronological order, and the user also You can operate Weibo likes, forwards, comments, and favorites.

4.2.4 Conch module
publishing: the user enters the Conch homepage by clicking the magic conch in the navigation bar. On the top of the Conch page is the question box for publishing conch, the emoticon buttons that can be inserted below and the reward points for the questions, and the navigation bar in the middle You can choose to view the latest release, resolved, to be resolved, my conch different filter conditions.

View Conch Questions: When the user clicks on any Conch question, the system jumps to a page displaying the specific information of the Conch. The user name, user name, release date, Conch question, reward points, question status, etc. of the posting user are displayed on the top, and displayed in the middle All the reply information to the question, the reply person's username, title, answer content, reply date, whether it is accepted, etc.

Answer conch questions: You can answer conch questions at the bottom of the detailed information page of conch questions, enter the reply answer in the input box, insert emoticon information, etc., and click reply to save the reply information in the database.

Accept the answer to the question: On the homepage of Conch Questions, users can jump to the Conch Questions page posted by the user by clicking My Conch Questions. In the Conch Questions page posted by themselves, they can choose the answer that they think is the most correct. After clicking Accept Modify the status of the conch, the accepted answer becomes the accepted answer, and the conch points of the adopter are increased.

4.2.5 Background administrator module
Administrator login: Administrators can click administrator login on the login page to jump to the administrator login page. After the administrator enters the account information and password information, if the user name and password are correct, it will jump to the administrator home page. Prompt if wrong.

Admin Homepage: The navigation bar is displayed at the top of the administrator homepage. In terms of page content, four charts are used to display the total number of Weibo, users, comments, conch, comments, answers, etc. and the number of the current month. The bar chart below It displays the number of the last 7 days from today.

User management homepage: Display the navigation bar at the top of the page, and the page content displays all user IDs, email addresses, nicknames, registration dates, last login dates, and user status. Considering the large number of users and the convenience of searching, the 10 pieces of user data are displayed on the page at a time, and a user search function is added at the same time. Users can search for users after entering the keywords of the user's nickname, and support vague queries. Search for users: Enter the keywords in the user's nickname on the user management page to search for users, and the system will display the part of the obtained user information where the nickname is the input keyword in red.

User ban: The administrator can click the ban button in the operation column of the user management page to ban the violating user. The administrator can enter the number of days for the ban. Before this date, the user cannot log in normally, and the administrator can Unblock users in advance by clicking Unblock.

Weibo management home page: administrators click Weibo management in the navigation bar, the system will jump to the user Weibo management page, displaying the Weibo information used in the system, administrators can also input keywords in Weibo content Search Weibo, and at the same time, you can delete Weibo with bad information, or restore the deleted Weibo.

Microblog search: Administrators can search for microblogs with the keyword in the microblog content by inputting keywords in the microblog content, and the keywords in the searched microblog content will be marked in red.

Weibo deletion: In the Weibo management page, the administrator can judge whether the Weibo is illegal or not according to the content of the Weibo. If the Weibo information contains bad information, the administrator can delete the Weibo through the delete button in the operation bar. You can also restore the deleted microblogs.

Conch Management Homepage: The administrator clicks Conch Management in the navigation bar to jump to the Conch Management page. The navigation bar is at the top of the page, and the page content displays all conch information, the conch search box, and the pagination box below, conch information Include the number, name of the publisher, what the conch is about, the date it was published, the status of the conch, and what actions it can take.

Conch Search: On the homepage of Conch Management, considering the large number of conch, it is difficult to find the problem, so the search function is set up. The administrator can enter the keywords in the conch content in the conch search box to search for the conch problem. In the display search When the results are obtained, the search keywords will be marked in red for easy viewing.

4.3 Database design
4.3.1 Overview
Microblog system database table mainly includes:
1. User table: used to store user's personal information, such as number, nickname, name, password. For mailbox and other information, use the user number as the primary key, as shown in Table 4-1.

2. Microblog follower table: used to save the user's follower information, with the follower ID as the primary key, as shown in Table 4-2.

3. Weibo table: used to save Weibo information, such as Weibo release time, Weibo content, Weibo likes, retweets, number of favorites, etc., with Weibo number as the primary key, as shown in Table 4-3.

4. Microblog collection table: used to save the microblog information collected by users, such as the microblog number, collection time, etc., with the collection number as the primary key, as shown in Table 4-4.

5. Comment table: save Weibo comment information, such as commenter ID, comment date, comment content, etc., with comment ID as the primary key, as shown in Table 4-5.

6. Points table: used to save the way users get points, such as obtaining points through daily login and posting Weibo, etc., with the point number as the primary key, as shown in Table 4-6.

7. Like table: used to save the like information of Weibo, mainly including the like number, like number, like Weibo number and other information. Use the like number as the primary key, as shown in Table 4-7.

8. Points flow table: used to save the information of points obtained by users, mainly including point number, user number, acquisition date and other information, with point number as the primary key, as shown in Table 4-8.

9. Forwarding table: used to save the information forwarded by the user, mainly including the forwarding number, forwarding person, Weibo number and other information, with the forwarding number as the primary key, as shown in Table 4-9.

4.3.2 Conceptual design
A user can post multiple microblogs, so there is a one-to-many relationship between the user table and the microblog table, as shown in Figure 4.12.
insert image description here

Figure 4.12 Correspondence between user table and Weibo table

A microblog can correspond to multiple likes, forwards, favorites and comments, so there is a one-to-many correspondence between the microblog table and the favorites, likes, forwards, and favorites tables, as shown in Figure 4.13.
insert image description here

Figure 4.13 Correspondence between Weibo table and Weibo operation table

A user can post multiple conches, and each conch question can correspond to multiple comments. As shown in Figure 4.14.
insert image description here

Figure 4.14 Correspondence between user table and conch table

4.3.3 Database table
1. User table: database table name USER_TAB, reference sequence name SEQ_USER.

Table 4-1 User table
insert image description here

2. Concern table: database table FRIEND_TAB, reference sequence name SEQ_FRIEND.

Table 4-2 Concern form
insert image description here

3. Weibo table: the database table name is WEIBO_TAB, and the reference index name is SEQ_WEIBO.

Table 4-3 Weibo table
insert image description here

4. Collection table: database table name COLLECT_TAB, reference index name SEQ_COLLECT.

Table 4-4 Collection table
insert image description here

5. Comment table: database table name COMM_TAB, reference index name SEQ_COMM.

Table 4-5 Comment Form
insert image description here

6. Integral table: database table name INTEGRAL_TAB, reference index name SEQ_INTEGRAL.

Table 4-6 Integral table
insert image description here

7. Like table: database table name LIKE_TAB, reference index name SEQ_LIKE.

Table 4-7 Like table
insert image description here

8. Integral flow table: database table name RECORD_TAB, reference index name SEQ_RECORD.

Table 4-8 Integral Flow Meter
insert image description here

9. Forwarding table: database table name TRANS_TAB, reference index name SEQ_TRANS.

Table 4-9 Forwarding table
insert image description here

Chapter 5 System Function Realization

5.1 Login system
On the system login registration page, when the user enters the mailbox, the mailbox will be sent to the background controller through Ajax, and the corresponding method in the Service layer will be called. The Dao layer interface is called in the Service method to find out whether the user mailbox has been registered. If it is registered, it will be displayed on the page through front-end javaScript to prompt the user that the mailbox has been registered. After entering the basic information and clicking register, the registration information entered by the user will be sent to the background controller through the browser, and the controller will control the request. Forward the page and pass the user registration information to the Service, initialize some basic information of the user in the Service, such as the default avatar, default status, initialize user points and other operations, assemble the user data source, and call the Dao layer method to save the user registration information as shown in the figure 5.1 shown. The core code is as follows:

user.setRegisterTime(nowDate());		//使用当前时间作为用户注册时间
	user.setLastLogin(nowDate());
	user.setBirthday("2017-1-1");
	User addUser = addIntegral(user, Constant.REGISTER);		//增加用户积分
	action = userDao.findIntegral(Constant.REGISTER);		//查找注册操作得到的PointAction
	record = new PointRecord(action, addUser.getEmail(), nowDate());
	addIntegralRecord(record);	//保存积分操作
userDao.saveUser(addUser); 	//保存用户注册信息

Login function, if you click the next automatic login password, after clicking login, first pass the user name and password information to the Service layer for business processing, and then call the Dao layer interface to judge whether the email address and password information are correct. If they are correct and click the next time Log in, save the mailbox name and password in the browser Cookie, save the logged-in user in the Session, and judge whether the user's current login time and last login time are on the same day in the Service that processes the user's login, if not the same day then Add login points for users, modify the number of points in the user database, and then jump to the homepage of Weibo, as shown in Figure 5.2. The core code is as follows:

findUser = userDao.findUserByEmailAndPassword(userId, password);
	if(findUser == null){
    
    
		throw new UserServiceException("用户名或密码错误");
	}else{
    
    
		Date lastLogin = findUser.getLastLogin();	//上次登陆时间
		Date now = nowDate();	//当前时间
		if(lastLogin.getYear()!=now.getYear() || lastLogin.getMonth()!=now.getMonth() || lastLogin.getDate()!=now.getDate()){
    
    
		//判断如果上次登陆时间和这次登陆时间不一样,则为用户增加登陆积分
		findUser=addIntegral(findUser, Constant.LOGIN);	//保存积分
		saveIRecord(findUser, Constant.LOGIN);	//保存积分记录
		findUser.setLastLogin(now);		//将上次登陆时间改为当前时间
		userDao.updateUser(findUser);	//更改用户信息
			}
}

insert image description here

Figure 5.1 User login and registration interface
insert image description here

Figure 5.2 Weibo home page interface

5.2 User information system
User basic information: As shown in Figure 5.3, when the user clicks to modify, the browser will submit the form form, send a request with the user's basic information to the controller of SpringMVC to receive the request, and assemble the data in the form form into a User Object, passed as a parameter to the corresponding method in the Service layer for processing, calling the Dao layer interface to modify the basic information of the user, and modify the User object information in the Session in the current server. The core code is as follows:

try {
    
    
		userDao.updateUser(user);
	} catch (DataAccessException e) {
    
    
		throw new UserServiceException("修改失败,请重试!");
	}

insert image description here

Figure 5.3 Modify user basic information interface

Change password: click change password on the user profile page, it will jump to the change password page as shown in Figure 5-4, the user can enter the user's current password, the front page sends an asynchronous request through Ajax, and the background controller receives the request , Obtain whether the user’s current password is correct from the database. If the password is incorrect, the front-end page will dynamically prompt the user to face the wrong password through javaScript. If the password is correct, the user can enter a new password and confirm the new password. Click Confirm to modify. The browser submits the form form, and passes the user's new password to the corresponding method in the background Service layer. In the Service method, the Dao layer interface is called to change the user password in the database and the user information in the server Session. The core code is as follows:

try {
    
    
		user.setPassword(newpwd);
		userService.updateUser(user); 
		session.setAttribute("loginUser", user);
		mav.addObject("msg", "修改成功");
	} catch (UserServiceException e) {
    
    
		e.printStackTrace();
}

insert image description here

Figure 5.4 Modify password interface

Modify user avatar: Click to modify the avatar in the user profile, it will jump to the page of modifying the avatar as shown in Figure 5.5, the user selects the avatar file, clicks upload, the form will transfer the image to the background controller, and save the user avatar On the server, it is judged that the user’s previous avatar is the default avatar of the system. If not, the user’s previous avatar picture is deleted, and the user’s new avatar address is saved in the user information, which is passed to the Service to call the Dao layer interface to modify the user’s profile in the database. Avatar information. The core code is as follows:

if(!(icon.isEmpty())){
    
    	//如果文件存在,isEmpty文件为空
			//保存文件目录
	String path = 	req.getServletContext().getRealPath("/")+"WEB-INF/jsp/face/"+user.getId()+ico	n.getOriginalFilename();
	File newFile = new File(path);
	//判断文件目录存在不存在,如果不存在就创建目录
	if(!(newFile.getParentFile().exists())){
    
    
		newFile.getParentFile().mkdirs();
	}
	try {
    
    
		icon.transferTo(newFile);	//转存文件		
		File oldIcon = new  File(req.getServletContext().getRealPath("/")+"WEB-INF/jsp/"+user.getImages());	//删除之前的头像	
		if(!(user.getImages().equals("face/boy.png") || user.getImages().equals("face/girl.png"))){
    
    
		//先判断用户之前的头像不是系统默认的头像,然后删除用户之前的头像
			if(oldIcon.exists()){
    
    
				oldIcon.delete();
				}
			}
			user.setImages("face/"+user.getId()+icon.getOriginalFilename());
			userService.updateUser(user);	//保存用户头像
			session.setAttribute("loginUser", user);	//将保存后的用户头像信息保存在用户session中
		} catch (Exception e) {
    
    	
			e.printStackTrace();
		}
	}else{
    
    
		mav.addObject("msg", "图片不存在");
}

insert image description here

Figure 5.5 Modify the avatar interface

Modify password: When the user clicks on the page to modify password, the browser jumps to the page of modifying password, as shown in Figure 5-6. The user first needs to fill in the answer according to the previously set password question, and the front page uses Ajax to input the user’s The answer to the secret security question is passed to the background controller, and the answer to the user’s secret security question in the database is judged. If the secret security answer is wrong, the user’s secret security answer is displayed on the page through javaScript. If the secret security answer is correct, the user can enter a new The security question and security answer of the user. After clicking Modify to submit the form, the browser sends a request to modify the user's security question and answer in the background database. The core code is as follows:

userService.updateUser(user);
	session.setAttribute("loginUser", user);
	mav.setViewName("forward:question_index");
mav.addObject("msg", "修改成功!");

insert image description here

Figure 5.6 Modify password protection interface

5.3 Microblog module
publishes microblogs: as shown in Figure 5.7 on the user homepage, users can publish microblogs, insert emoticons into the microblog information, or choose to insert a picture. On the front page, emoticons are dynamically generated using javaScript The div tag is displayed on the page. When the user clicks publish, the browser sends a request to transfer the microblog information and picture information in the front page form to the background controller, save the picture information in the server, and only save the picture path in the database , get the current login user from the Session, assemble the microblog data source, pass the data source into the Service, call the Dao layer interface to save the microblog information in the database. The core code is as follows:

if(!(pic.isEmpty())){
    
    	//如果文件存在,isEmpty文件为空
	//保存文件目录
	String path = req.getServletContext().getRealPath("/")+"WEB-inf/jsp/upload/pic/"+user.getId()+pic.getOriginalFilename();
	File newFile = new File(path);
	//判断文件目录存在不存在,如果不存在就创建目录
	if(!(newFile.getParentFile().exists())){
    
    
		newFile.getParentFile().mkdirs();
	}
	try {
    
    
		pic.transferTo(newFile); //转存文件
		weibo.setImage("upload/pic/"+user.getId()+pic.getOriginalFilename());
	} catch (Exception e) {
    
    
		e.printStackTrace();
		}
}else{
    
    
	//没有带图片
	weibo.setImage("null");
}
try {
    
    
		//保存微博信息
		weibo.setUser(user);
		weiboService.publishWeibo(weibo);	//保存微博信息
		user.setBlogNumber(user.getBlogNumber()+1);		//将用户的微博数+1
		userService.updateUser(user);		//保存更改后的用户信息
		session.setAttribute("loginUser", user);	
		mav.addObject("msg", "发布成功!");
	} catch (Exception e) {
    
    	
		e.printStackTrace();
		mav.addObject("msg", e.getMessage());
	}

insert image description here

Figure 5.7 Publish Weibo Information Interface

Search Weibo: As shown in Figure 5.8, enter a keyword in the search box on the homepage of Weibo, click Search to submit the form, the browser sends a request to pass the keyword to the background controller, and query related Weibo in the database through vague query information. In the specific method in the Service layer, call the Dao layer interface to obtain relevant microblog information, traverse the collection, assemble the basic information of the microblog and the publisher object, convert the expression in the microblog into a corresponding gif image, and adjust the time format of the microblog as Corresponding to the format, modify the search keywords in the Weibo content to be displayed in red, and return the modified data to the front page for display, as shown in Figure 5.9. The core code is as follows:

User user = (User) session.getAttribute("loginUser");
	if("weibo".equals(ac)){
    
    
		mav.setViewName("seachWeiboPage");
	}else if("user".equals(ac)){
    
    
		mav.setViewName("seachUserPage");
	}
	try {
    
    
		Map<String, Object> map = userService.seachWeiboAndUser(skey,pag,ac);
		mav.addObject("map", map);	
		List<User> userTuiJian = weiboService.findUserTuiJian(user.getId());
		mav.addObject("tuijian", userTuiJian);
		} catch (Exception e) {
    
    
			e.printStackTrace();
	}

insert image description here

Figure 5.8 Publish Weibo Information Interface

insert image description here

Figure 5.9 Search Weibo display interface

Weibo operation; click on Weibo to like, forward and save function types, submit the Weibo id request to the background controller through Ajax, obtain the login user information from the Session, and pass the parameters to the corresponding method of the Service through the Weibo The different operations of the blog call the corresponding Dao layer interface to save the likes, retweets and collection information of Weibo in the database. After clicking on the comment, jump to JavaScript through the click event on the foreground page, send an asynchronous request to the background controller through Ajax, and pass the Weibo id to the corresponding method in the Service layer. Use the Dao layer interface to find the corresponding Weibo number in the database. For the comment information, the pagination of microblog comments is controlled by the corresponding PageBean class, the number of items to be displayed in the pagination is controlled by the SQL statement at the database layer, and the json data is passed in the controller to the front page for display. At the end of the comment information, users can publish their own comments, add emoticons, click publish to submit the form to the background controller, and call the Dao layer interface in the background code to save the user's comment information. As shown in Figure 5.10. The core code is as follows:

comm.setBeCommentId(dao.findUserIdbyWId(comm.getWeiboId()));
	comm.setCommentLike(0); 	//默认点赞数为0
	//保存评论信息
	dao.saveWeiboComm(comm);
	Weibo weibo = dao.findWeiboBywId(comm.getWeiboId());
	//查找微博评论数
	commNum = dao.findCommNum(comm.getWeiboId());
	weibo.setComnum(commNum);
	//更新微博评论数目
dao.updateWeibo(weibo);

insert image description here

Figure 5.10 Weibo text operation interface

Personal Weibo: As shown in Figure 5.11: In the navigation bar at the top of the page, you can click to enter the user's personal homepage to view my Weibo. In the middle of the page, the navigation bar is displayed at the top of the page, and the basic information of the user is displayed below, and the posts posted by the user are displayed in the middle. Weibo, clicking on the picture inserted in Weibo can also enlarge the picture through JavaScript, and display the friends recommended by the system for the user on the right side of the page. The request sent after clicking the My Weibo button will be received by the background controller, and the user id of the currently logged-in user will be obtained from the server Session, passed to the Service layer, and the Dao layer interface will be called in the Service layer to obtain the ID of the currently logged-in user from the database. The microblog information is assembled into a List collection, traverse the List collection, change the date format of the microblog data source, call the tool class to replace the expression in the text of the microblog with the corresponding picture information, and use the Oralce database in the pagination of the microblog Pseudo-column to obtain the microblog information of the corresponding interval, realize the pagination of the database layer, pass all the data that needs to be displayed on the page to the controller, and the controller then encapsulates the data in the Response response and passes it to the front page. The core code is as follows:

List<Weibo> list = weiboService.findHomeWeibo(0, page, null);
	list = FaceFormat.formt(list);
	for(int i=0;i<list.size();i++){
    
    
		long uId = list.get(i).getU_id();	//获取用户id
		User weibo_user = userService.findUserById(uId);
		list.get(i).setUser(weibo_user); 	//将user信息组装到weibo类中
		boolean b = weiboService.userLikeWeibo(list.get(i).getId(), user.getId());
		list.get(i).setB(b);
		//重新查找未读私信数目
		Map<String, Object> alerts = userService.alerts(user.getId());
		session.setAttribute("alerts", alerts);
	}
	int pageNumber = 0;
	page.setTotalPage(pageNumber/10+1); 	//确定所有的微博共有多少页
List<User> userTuiJian = weiboService.findUserTuiJian(user.getId());

insert image description here

Figure 5.11 Personal Weibo interface

5.4 Friend module
View friend microblog: click on my friend in the page navigation bar to jump to the friend microblog page. In the background controller, first obtain the id value of the currently logged-in user from the Session, and pass it to the Service. In the Service Call the Dao layer method to first find all the friend information of the corresponding user in the friend table of the database, and then check the Weibo information corresponding to these friends in the database Weibo table in reverse order of Weibo release time, and list all the found Weibo Information and published user information are encapsulated into a List collection, traverse the List collection to modify the Weibo date, convert Weibo emoticons into corresponding picture names, pass the processed collection to the controller, and the controller responds with all the assembled data Go to the foreground page, and use the C tag to traverse the List in the foreground page to display the Weibo data, as shown in Figure 5.12. The core code is as follows:

List<Weibo> list = friendService.findFriendWeibo(user.getId(), page);
	list = FaceFormat.formt(list);
	for(int i=0;i<list.size();i++){
    
    
		long uId = list.get(i).getU_id();	//获取用户id
		User weibo_user = userService.findUserById(uId);
		list.get(i).setUser(weibo_user); 	//将user信息组装到weibo类中
		boolean b = weiboService.userLikeWeibo(list.get(i).getId(), user.getId());
		list.get(i).setB(b);
		comm = FaceFormat.commFormt(comm);
		list.get(i).setComm(comm);			list.get(i).setStr_pubTime(TimeFormat.dateToString(list.get(i).getStr_pubTime())
	}
	int pageNumber = friendService.findWeiboNumber(user.getId());
	page.setTotalPage(pageNumber/10+1); 	//确定所有的微博共有多少页
List<User> userTuiJian = weiboService.findUserTuiJian(user.getId());

Follow function: When the user logs in to the system, he can select the user who needs to follow from the recommended users on the right side of the page. After clicking Follow, the front page sends an asynchronous request through Ajax technology to send the user id of the user to be followed to the background controller. Obtain the logged-in user information in the Session from the server, pass the logged-in user's id and the followed user's id to the corresponding method in the Service layer, process it in the corresponding method of the Service layer, assemble the friend information data source, and call the Dao layer interface Save the user's attention information, update the user's attention number at the same time, update the number of fans of the user who is followed, and then modify the page text information attention to followed through javaScript on the front page. The core code is as follows:

User user = (User)session.getAttribute("loginUser");
	long bId = Long.parseLong(attId);
	User bUser = userService.findUserById(bId);	
	weiboService.operationUser(operation, user, bUser);

Unfollow: and follow function type, click My Friends in the navigation bar, click Follow in the middle, you can view all the friends I follow, their number of friends and their personal information, as shown in Figure 5.13, click Unfollow , pass the friend id to the background controller through Ajax, obtain the user information in the request in the controller, pass the friend id and user id to the corresponding method in the Service layer, and call the Dao layer interface to correspond to the user id and friend id The friend information of the user is deleted, and the number of followers of the user and the number of fans of the user being followed are changed at the same time. Then return the response to refresh the friend list on the foreground page.

else if(operation.equals("QXGZ")){
    
    
		//取消关注用户操作
		dao.canUser(aId,bId);
		aUser.setAttention(aUser.getAttention()-1);		//a用户关注数-1
	bUser.setFans(bUser.getFans()-1);		//b用户粉丝数-1	
}

Blocking users: Similar to unfollowing users, except that in the Dao layer interface, the existing user records are not deleted but logically deleted, that is, the corresponding record status in the friend table is modified, and the private messages and Weibo published by the blocked user The information will not be seen by blocked users. The core code is as follows:

else if(operation.equals("LH")){
    
    
		//拉黑用户 不接收该用户的私信
		friendDao.updateFriendToBlack(aId, bId);
		friendDao.updateFriendState(aId, bId);
}

insert image description here

Figure 5.12 Friend Weibo Information Interface

insert image description here

Figure 5.13 Friends list interface

Private message: You can view the number of unchecked private messages of the current login user on the page of recommended users, as shown in Figure 5.14, the number of unread private messages is through all private message information in the database for all recipients of the current login user, and the information status is For unread private messages, pass the obtained value to the front page, and all displayed values ​​on the front page are obtained from the response sent back from the server through EL expressions. Click the unread private message or click the private message button in the friend list shown in Figure 5.13 to jump to the user's private message page. The core code is as follows:

List<User> userList = dao.findUserByMessage(aId);
	if(bId == -1 && userList.size()!=0){
    
    
		//通过点击私信进入
		bId = userList.get(0).getId();
	}
	List<Message> list = dao.findMessageById(aId, bId);
	for(int i=0;i<list.size();i++){
    
    
		list.get(i).setUserA(userDao.findUserById(list.get(i).getUserAId()));
		list.get(i).setUserB(userDao.findUserById(list.get(i).getUserBId()));
	list.get(i).setMessageDate(TimeFormat.dateToString(list.get(i).getMessageDate()));
	}
	list = FaceFormat.messageFormt(list);
User user = userDao.findUserById(bId);

insert image description here

Figure 5.14 User unread private message interface

View private messages: As shown in Figure 5.15, when a user clicks on a private message to follow a friend, the background controller jumps to my private message user page. The left side of the page displays the latest private message information of the user, and the right side of the page displays all the private messages that have been sent. Click on a user in the list to send a private message to the user directly, and emoticons are allowed in the private message. In the background code, pass the user id to send the private message and the login user id obtained from the Session to the corresponding method in the Service layer, call the Dao layer interface to find all the private message records related to the user in the database and modify it at the same time The status of all private messages is read, assemble the obtained records into a collection, traverse the collection and call the tool class to modify the date format of the private message and the expression format in the text, and at the same time obtain all users who have private message records with the current login user from the database , return the assembled collection to the controller, the controller responds the data to the front page, traverses the data in the collection, and displays it on the front JSP page. The core code is as follows:

for(int i=0;i<userList.size();i++){
    
    
		//查找来自该用户的未读私信
		userList.get(i).setUnReadMessage(dao.findURMNByUID(aId, 	userList.get(i).getId()));
}

insert image description here

Figure 5.15 User private message interface

Send a private message: the user first selects the user to send, enters the private message information to be sent, and can insert emoticons in the private message. After clicking send, the form will be submitted. The browser sends the request to the background controller, and the controller obtains the ID of the sending user And receive the user's id, call the method in the Service layer, assemble the data source as private message information, set the private message information as unread, call the Dao layer interface in the corresponding method in the Service layer to save the private message information in the database. The core code is as follows:

friendService.sendMessage(message);
	List<User> userTuiJian = weiboService.findUserTuiJian(user.getId());
	mav.addObject("tuijian", userTuiJian);
	//查找用户有私信的记录
	Map<String, Object> map = friendService.findMessageById(user.getId(), userBId);
	@SuppressWarnings("unchecked")
	List<Message> Messagelist = (List<Message>) map.get("list");
	User bUser = (User) map.get("bUser");
	@SuppressWarnings("unchecked")
	List<User> attUser = (List<User>)map.get("attUsers");

Search users: In the search user page, users can enter keywords of user nicknames to fuzzily query related users. When users enter user nicknames to be queried, the browser sends a request with keywords and other information to jump to a specific method in the controller , the method processing logic in Service is called inside the controller method, and the business layer calls the search method in the Dao layer interface to find users whose user nicknames contain keywords, assemble the corresponding users obtained from the database into a set, and traverse the set to The keywords contained in the user's nickname are changed to red, the controller returns a response and jumps to the search result page, and traverses the collection to display all the found user information. As shown in Figure 5.16. The core code is as follows:

Map<String, Object> map = userService.seachWeiboAndUser(skey,pag,ac);
		mav.addObject("map", map);
		List<User> userTuiJian = weiboService.findUserTuiJian(user.getId());
		mav.addObject("tuijian", userTuiJian);

insert image description here

Figure 5.16 Search UI

User homepage: On the page, clicking any user's name or profile picture will jump to the corresponding user's personal homepage. The user's personal homepage displays the user's personal information and the user's latest Weibo, arranged in reverse chronological order, and the user also You can operate Weibo likes, forwards, comments, and favorites. In the acquired code, when a user clicks on another user's avatar or name, the browser sends a request carrying the user id to the background controller. The controller calls the corresponding method in the Service, calls the Dao layer interface in the Service method to view the basic information of the user and the user's Weibo information from the database, and stores all the data in the collection. Return to the controller, and the controller carries the data back to the front page for display, as shown in Figure 5.17. The core code is as follows:

List<Weibo> list = friendService.findFriendWeibo(user.getId(), page);
	list = FaceFormat.formt(list);
	for(int i=0;i<list.size();i++){
    
    
		long uId = list.get(i).getU_id();	//获取用户id
		User weibo_user = userService.findUserById(uId);
		list.get(i).setUser(weibo_user); 	//将user信息组装到weibo类中
		boolean b = weiboService.userLikeWeibo(list.get(i).getId(), user.getId());
		list.get(i).setB(b);
		comm = FaceFormat.commFormt(comm);
		list.get(i).setComm(comm);		  			 	list.get(i).setStr_pubTime(TimeFormat.dateToString(list.get(i).getStr_pubTime()));
}

insert image description here

Figure 5.17 User homepage interface

5.5
Release of the Conch module: When the user enters the Conch homepage, the browser page sends a request to the backend controller to call a specific method in the business layer, and the Service calls the Dao layer interface to find conch questions related to different filter conditions in the database, and Encapsulate the found problems in a collection, send the server response through the controller, jump to the Conch homepage, and display all Conch problems in a loop. If the user needs to publish a question, after filling in the description of the question and the number of points to be rewarded, click Publish, and the browser submits the form data to the background controller. In the Service layer, it is first judged whether the user's conch points are greater than the reward points, if less than Reward points will return to the browser page to prompt the user that the points are insufficient. If the points are enough, call the Dao layer interface to save the user's conch questions in the database, and at the same time reduce the user's conch points to modify the user's basic information. The core code is as follows:

//海螺分页
	//获取海螺总数
	int num = userService.conchNum(user.getId(), conchOperation);
	if(num%5 == 0){
    
    
		page.setTotalPage(num/5);
	}else{
    
    
		page.setTotalPage(num/5+1);
	}
	page.setPage(1);	//每5页一分页
	page.setMinPage(1*5-4);
	page.setMaxPage(1*5);
	//查找海螺显示
	Map<String, Object> map = userService.conchIndex(user.getId(), conchOperation ,page);
	List<User> userTuiJian = weiboService.findUserTuiJian(user.getId());

insert image description here

Figure 5.18 Conch home page interface

View conch problems: When a user clicks on a specific problem on the conch homepage, the browser sends a request to the background controller to call the method corresponding to the Service layer, and calls the Dao layer interface in the Service layer to view the specific information of the conch through the number of the conch problem. The user id who posted the question looks up the corresponding poster information in the database, and the server returns a response to the browser, displaying the specific information of the conch, and the user name, user title, release date, conch question, reward points, and question of the posting user are displayed on the top The status of the question, etc., displays all the reply information of the question in the middle, the reply person's user name, title, answer content, reply date, whether it is accepted, etc., as shown in Figure 5.19. The core code is as follows:

List<WeiboComm> list = weiboDao.findWeiboComm(conchId, 0, 20);
	list = FaceFormat.commFormt(list);
	for(int i=0;i<list.size();i++){
    
    			                                  	list.get(i).setCommentDate(TimeFormat.dateToString(list.get(i).getCommentDate()));
	list.get(i).setCommUser(userDao.findUserById(list.get(i).getCommentId()));
	}
	map.put("conchComm", list);

insert image description here

Figure 5.19 view the specific interface of the problem

Answer conch questions: You can answer conch questions at the bottom of the detailed information page of conch questions, enter the reply answer in the input box, insert emoticon information, click reply to submit the form, the browser requests to carry the form data to the background controller, and is controlled The specific method in the server receives, obtains the user number in the Session, assembles the data source of the reply information, passes the parameters to the Service, and calls the Dao layer interface in the Service to save the reply information of the conch, as shown in Figure 5.20. The core code is as follows:

comm.setCommentState(100); //100回复正常未采纳 101回复正常被采纳
weiboDao.saveWeiboComm(comm);

insert image description here

Figure 5.20 Reply Conch question interface

Accept the answer to the question: On the homepage of Conch Questions, users can click My Conch Questions to jump to the Conch Questions page posted by the user themselves. In the Conch Questions page posted by themselves, they can choose the answer they think is the most correct. The answer becomes an accepted answer, increasing the conch points of the adopter, as shown in Figure 5.21. In the background code, when the user clicks to accept, the browser request carrying the conch question id and question reply information is received by the specific method in the background controller , Call the Service layer in the controller, call the Dao layer interface in the business layer to modify the status of the conch problem in the database to solved, modify the comment status of the accepted user in the comment table to be accepted, and refresh the front conch problem page. The core code is as follows:

//设置海螺状态为1
	userDao.setConchState(conchId);
	//设置海螺评论状态为101
	userDao.setConchComm(commId);
	//为用户增加海螺积分
	Conch conch = userDao.findConchById(conchId);
	User user = userDao.findUserById(userDao.findUserIdByCommId(commId));
	user.setConchIntegral(user.getConchIntegral()+conch.getcNumber());

insert image description here

Figure 5.21 Accept question answer interface

5.6 Background administrator module
administrator login: the administrator can click the administrator login on the login page to jump to the administrator login page as shown in Figure 5.22. After the administrator logs in, the page sends a request to the background controller, and the background The Controller layer receives the request, calls the method in the business layer with the user name and password as parameters, calls the Dao layer interface in the Service layer and queries in the administrator account table in the database, returns the administrator class if it exists, and throws it if it does not exist When an exception occurs, the exception is thrown layer by layer, received in the controller layer, and the error information is saved in the return value of the method, and the page prompts. If the user name and password are correct, it will jump to the processing method of the administrator's home page in the Controller In the processing method of the administrator's home page, the data to be displayed is obtained and displayed. The core code is as follows:

@RequestMapping("admin_login")
	public String adminIndex(){
    
    
		return "admin/adminlogin";
}
 

insert image description here

Figure 5.22 Administrator login interface

Administrator homepage: After logging in, the system will jump to the administrator homepage, and the navigation bar will be displayed on the top of the homepage. In terms of page content, four charts will be used to display the total number of Weibo, users, comments, conch, comments, answers, etc. And the number of the current month, the bar chart below shows the number of the 7 days closest to today. The background first jumps to the processing method corresponding to the administrator's home page in the Controller layer, calls the corresponding method in the Service layer to obtain the home page display data, assembles the obtained data into a Map collection, and calls the Dao layer in the service layer The method to obtain the user, Weibo, comment, answer and other data that needs to be displayed on the home page is stored in the Map collection, the return value data is obtained in the control layer and stored in the server response, and returned to the front page to display the data using EL expressions , as shown in Figure 5.23. The core code is as follows:

//首页展示数据
	try {
    
    
		Map<String, Object> map = adminService.indexDate();
		mav.addObject("map", map);
	} catch (UserServiceException e) {
    
    
		e.printStackTrace();
}

insert image description here

Figure 5.23 Administrator home page interface

User management home page: The background code calls the corresponding method in the Service layer, and the Service method calls the Dao layer interface to interact with the database, obtain all user information in the database and encapsulate it into a List collection, and return it to the Controller layer to respond to the user List collection to the browser In the page, the user information is traversed and displayed through the c tag. The paging of the page uses the custom paging class PageBean to save the paging information, and performs paging at the database layer to obtain 10 pieces of data at a time. The core code is as follows:

int num = 0;
	if(ukey == null){
    
    
		num =  adminService.findUserNum();
	}else{
    
    
		num = adminService.findUserNum(ukey);
	}
	if(num%10 == 0){
    
    
		pageBean.setTotalPage(num/10);
	}else{
    
    
		pageBean.setTotalPage(num/10+1);
	}
	pageBean.setPage(page);
	pageBean.setMinPage(page*10-9);
	pageBean.setMaxPage(page*10);
	List<User> list = null;
	if(ukey == null){
    
    
		list =  adminService.userManage(pageBean);
	}else{
    
    
		list = adminService.userManageByKey(pageBean, ukey);
	}
	mav.addObject("userList", list);
mav.addObject("pageBean",pageBean);

insert image description here

Figure 5.24 User Management Interface

Search for users: Enter the keywords in the user's nickname on the user management page to search for users, and the system will display the part of the obtained user information where the nickname is the input keyword in red. In the background code, clicking Search will pass the user nickname keyword entered by the administrator to the background controller, call the corresponding search user method in the Service layer in the controller, and call the Dao layer interface in the Service layer in the database Obtain users through fuzzy queries. And return the obtained data layer by layer, respond to the front page in the Controller, and then display it on the page, as shown in Figure 5.25. The core code is as follows:

list = adminDao.findAllUserByKey(key,page.getMinPage(),page.getMaxPage());
	for(int i=0;i<list.size();i++){
    
    
		list.get(i).setNickName(FaceFormat.keyFormt(list.get(i).getNickName(), key));
}

insert image description here

Figure 5.25 Admin search user interface

User ban: The administrator can click the ban button in the operation column of the user management page to ban the violating user. The administrator can enter the number of days for the ban. Before this date, the user cannot log in normally, and the administrator can Unblock users in advance by clicking Unblock. The specific page is shown in Figure 5.26. In the background code, the Dao layer interface is called in the Service layer to change the user status and ban date. Unbanning is similar to banning users, so no specific instructions will be given. The core code is as follows:

mav.setViewName("redirect:userManage");
	try {
    
    
		adminService.FJUser(uId, day);	//uId封禁用户编号,day封禁天数
	} catch (UserServiceException e) {
    
    
		e.printStackTrace();
	}
mav.addObject("page", 1);

insert image description here

Figure 5.26 Ban user interface

Weibo management home page: administrators click Weibo management in the navigation bar, the system will jump to the user Weibo management page, displaying the Weibo information used in the system, administrators can also input keywords in Weibo content Search Weibo, and at the same time delete the Weibo with bad information, or restore the deleted Weibo. The Weibo management page is shown in Figure 5.27. In the background code, when the user clicks Weibo management in the navigation bar, The browser will send the corresponding request to the Controller of the SpringMVC framework for more processing methods, call the method of displaying all microblogs in the Service layer in the controller, and then call the Dao layer method in the Service layer to obtain all Weibo information, in terms of paging, does not use the method of paging in the front-end page, but uses Oracle’s pseudo-column to do paging in the database, obtains 10 pieces of data at a time, and finally responds to the obtained Weibo information in the Controller To the browser, the browser displays Weibo information through c tag traversal. The core code is as follows:

String nkey = "";
	if(key == null){
    
    
		nkey = "1=1";
	}else{
    
    
		nkey = "m_body like '%"+key+"%'";
	}
	list = adminDao.findWeiboByKey(nkey, pageBean.getMinPage(), pageBean.getMaxPage());
	list = FaceFormat.formt(list);
	for(int i=0;i<list.size();i++){
    
    
						list.get(i).setStr_pubTime(TimeFormat.timeFormat(list.get(i).getPubTime()));
		list.get(i).setUser(userDao.findUserById(list.get(i).getU_id()));
		if(key != null){
    
    
		list.get(i).setBody(FaceFormat.keyFormt(list.get(i).getBody(), key));
		}
}

insert image description here

Figure 5.27 Weibo management interface

Microblog search: administrators can search for microblogs with the keyword in the microblog content by inputting keywords in the microblog content, and the keywords in the searched microblog content will be marked in red, as shown in the specific page As shown in 5.28, in the background code, a specific method in the controller receives the microblog search request sent by browsing, calls the corresponding method in the Service layer, passes keywords as parameters to the Dao layer interface, and searches in the Dao layer interface The microblog content in the database microblog table contains the microblog information of the keyword, and the corresponding microblog is found in the database through fuzzy query. Then encapsulate the found microblog information into the List collection, and return to the corresponding method in the Controller layer layer by layer, and respond the data to the browser in the method, and the browser receives the response and displays the data through the c tag on the page. The core code is as follows:

if(key == null){
    
    
		nkey = "1=1";
	}else{
    
    
		nkey = "m_body like '%"+key+"%'";
	}
list = adminDao.findWeiboByKey(nkey, pageBean.getMinPage(), pageBean.getMaxPage());

insert image description here

Figure 5.28 Administrator search Weibo interface

Weibo deletion: In the Weibo management page, the administrator can judge whether the Weibo is illegal or not according to the content of the Weibo. If the Weibo information contains bad information, the administrator can delete the Weibo through the delete button in the operation bar. Blog or you can restore the deleted Weibo. When the user clicks to delete, the page will send a request to the server with parameters such as the Weibo number, and the request will be received by the corresponding method in the controller, and the Weibo number will be As a parameter, use the corresponding method in Service, call the Dao layer interface in the method, and modify the status of the microblog corresponding to the microblog number in the database to be deleted. Restoring a microblog is similar to deleting, except that the state of the corresponding microblog information in the database is modified to Normal can be. The core code is as follows:

if("sc".equals(ac)){
    
    
		adminDao.upWeiboWithState(wId, 1);
	}else if("hf".equals(ac)){
    
    
		adminDao.upWeiboWithState(wId, 0);
}

Conch management home page: the administrator clicks the conch management in the navigation bar to jump to the conch management page, as shown in Figure 5.29, the navigation bar is at the top of the page, and the page content displays all conch information, the conch search box, and the bottom Conch information includes serial number, publisher name, conch content, release date, conch status, and operations that can be performed. In terms of background code, when the user clicks conch management in the navigation bar, the browser sends a request, request Received by the corresponding method in the controller, call the Dao layer interface in the Service to find all the conch information in the database conch table, save it in the List collection, traverse the List collection to assemble the publisher user information, modify the date format, etc., and finally assemble No.'s List collection is returned to the Controller, and the response is sent to the browser to jump to the conch management home page, and the searched conch information is displayed by traversing through the c tag. Because the paging method used in the system is the same, it will not be described here. The core code is as follows:

int num = adminService.findConchNum(ckey);
	if(num%10 == 0){
    
    
		pageBean.setTotalPage(num/10);
	}else{
    
    
		pageBean.setTotalPage(num/10+1);
	}
	pageBean.setPage(page);
	pageBean.setMinPage(page*10-9);
	pageBean.setMaxPage(page*10);
List<Conch> list = adminService.findConch(pageBean, ckey);

insert image description here

Figure 5.29 Conch Management Home Page Interface

Conch Search: On the conch management homepage, considering the large number of conch, it is difficult to find the problem, so the search function is set up. The administrator can search for conch problems by entering the keywords in the conch content in the conch search box. In the display search When the results are obtained, the search keywords will be marked in red for easy viewing. The specific page is shown in Figure 5.30. In the background code, when the user enters a keyword and clicks to search, the browser sends a request to the specified method in the controller to receive it, calls the corresponding method in the Service layer in the Controller to process the business logic, and then calls the Dao layer interface in the Service layer to pass The fuzzy query looks up the corresponding conch information in the conch table of the database, and finally responds the found conch information to the browser in the Controller, and traverses and displays the data through the c tag on the page. Because the system uses the same paging method, so I won't go into details. The core code is as follows:

if(key == null){
    
    
		nkey = "1=1";
	}else{
    
    
		nkey = "CONCHBODY like '%"+key+"%'";
	}
	System.out.println(nkey);
	list = adminDao.findConchByKey(nkey, pageBean.getMinPage(), pageBean.getMaxPage());
list = FaceFormat.conchFormt(list);

insert image description here

Figure 5.30 Conch search interface

Chapter 6 System Testing

6.1 System test overview
In the code writing stage, unit tests are mainly used to test whether the code has defects, whether the system functions can run normally, and whether the software can achieve the expected purpose. After the completion of the software system, write the test cases of the corresponding modules. Steps to test whether there are defects in the system, while using black-box testing and white-box testing to improve system functions, optimize software codes, and improve the quality of software systems.

6.2 Test cases
6.2.1 User registration module
Table 6-1 User registration
insert image description here

6.2.2 User login module
Table 6-2 User login
insert image description here

6.2.3 Modify user information module
Table 6-3 Modify user information
insert image description here
insert image description here

6.2.4 Weibo module
Table 6-4 User Weibo module
insert image description here
insert image description here

6.2.5 User friend module
Table 6-5 User friend module
insert image description here

6.2.6 User Conch Module
Table 6-6 User Conch Module
insert image description here

6.2.7 Administrator module
Table 6-7 Administrator module
insert image description here
insert image description here

6.3 Test Analysis
Omit

6.4 Summary of this chapter
In this chapter, the test cases of the system are mainly written to test whether the system can realize the designed functions and whether it contains various defects. After testing the system according to the test cases, it is found that there are few visible defects in the system , some discovered defects have also been resolved, but there is no system that is absolutely free from defects, so the defects of the system must be continuously discovered in the later use.

Chapter 7 Summary
Omitted

References
[1] Jia Wenxiao, Deng Junjie. Analysis of Java-based Web Development Technology [J]. Electronic Testing, 2016 [
2] Li Chuanyang. Design and Implementation of Weibo Analysis System [D]. Beijing University of Posts and Telecommunications, 2015
[3] Liu Yunchen. Website Design and Construction [M]. Tsinghua University Press, 2008
[4] Qin Yahua. Design and Implementation of Microblog Website Based on WEB2.0 [D]. Beijing University of Technology 2012
[5] Chen Ling, Xia Xun. Using Mybatis's Dynamic SQL to Realize Physical Paging[J]. Digital Technology and Application. 2011(11) [6]
Sa Shixuan, Wang Shan. Introduction to Database Systems (Third Edition) [M]. Beijing: Higher Education Press, 1998
[7] Java-based database access technology research [J]. Science and Technology Information. 2009 (04) [
8] Zhang Feng. Web application research and implementation based on Ajax technology and J2EE framework [D]. China University of Geosciences 2008
[9] Network programming based on Java multithreading technology [J]. Computer programming skills and maintenance. 2009 (22)
[10] Li Wei. Design of a small and practical instant network chat communication system [J]. Journal of Yangtze University ( Natural Science Edition). 2011(12)
[11] Zhong Ruiqi. Analysis and Design Based on Weibo Embedding Small Partner Reading Network [D]. South China University of Technology 2011 [
12] Written by Wang Shaofeng. Object-Oriented Technology UML Course [M]. Tsinghua University University Press, 2004
[13] Xu Chunmian. Research on issues related to website development [J]. Communication World. 2015 (09) [14] Zhang Yu, Wang
Yinghui, Zhang Xiangnan. Design and implementation of MVC framework based on Spring [J]. Computer Engineering. 2010(04)
[15] Hu Yiqiao, Zhang Liping. Choice of J2EE Development Model [J]. Computer System Application. 2002 (08) [16] Wang
Liai. Design and Implementation of "Java Programming" Course Website [J]. Computer Knowledge and Technology . 2016(27)
[17] Rong Yandong. Application Research on Mybatis Persistence Layer Framework [J]. Information Security and Technology. 2015(12)

Acknowledgments
omit


5. Source code download:

The source code and thesis of this project are as follows, friends in need can click to download. If the link fails, you can click the card below to scan the code to download it yourself.

serial number A full set of resources for graduation design (click to download)
The source code of this project Design and implementation of BS architecture microblog system based on javaEE+SSM+MySql (source code + document)_JAVAEE_SSM_BS architecture microblog system.zip

Guess you like

Origin blog.csdn.net/m0_66238867/article/details/125471185