A forum login module to explain how to use spring
Although the login function is simple, although the module is small, it basically includes the operation of the general Web application. Covers persistent layer data access (database related operations), Business Layer transaction management (database operations rollback, etc.), presentation layer MVC, and other enterprise operations.
Introduction to Instance Features
The basic process of landing is not elaborate, to say is the successful landing, record the user's success log, update the user's left after the login time and IP, and to add 5 points to the user, and then redirect to the Welcome interface, the page flow as follows
The persistence layer has two DAO classes, namely Userdao and Loginlogdao, corresponding to a business class UserService in the business layer, with a Logincontroller class and two JSP pages in the presentation layer, is landing page login.jsp and welcome on the interface main.jsp.
Let's take a look at the timing diagram for the entire process.
1. The user first accesses login.jsp, returns the login page with username/password form;
2. The user enters the user name and the password in the landing page, submits the form to the server, spring responds to the login request according to the configuration call Logincontroller Controller;
3.LoginController calls the Userservice#hasmatchuser () method, UserService internally through the call to the persistence layer Userdao to complete the specific database access operations;
4. If there is no matching user, redirect to the login.jsp page and report the error, otherwise the next step;
5.LoginController calls the Userservice#finduserbyusername () method, loads the matching user object and updates the last login time and login IP;
6.LoginController call Userservice#loginsuccess () method, the login successful business processing: Specifically, first call Userdao#updatelogininfo () to add 5 points for the user, Then create a Loginlog object and use Loginlogdao to insert it into the database;
7. Redirect to the Welcome screen main.jsp.
Development environments that need to be prepared before development
Linux:ubun 14.04 64bitide:intellij Idea 14.03jdk:1.7.40mysql:5.5.44tomcat:7.0.47maven:3.0.5
Spring Learning Note 01