Objective
Recently in learning Spring Boot, before someone said that the best way to learn programming is to write their own programs, there is a predecessor recommend themselves to do a simulation of online ticketing system services. I made one myself.
The implementation of the project uses spring Boot + MyBatis, integrating spring Security and JWT to enable user authentication and authorization.
The project structure is as follows:
Design ideas
There are three main objects: users, tickets and orders.
The user has ID, user name, password, avatar at the server address URL and other personal information. User's methods are: Register (/customer/register), login (/customer/login), view user profile (/customer/myprofile), upload Avatar (/customer/uploadavatar).
The ticket has ID, train, start, destination, departure time, arrival time, seat type, seat number, price, whether it is booked and user ID properties. The method is to find the available train information (/ticket/search) based on the originating station, destination and departure date. This uses the MyBatis plugin pagehelper to do paging queries.
The attributes of the order are: ID, user, ticket. The order method is: Purchase ticket (/order/new), Refund (/order/roll), check "My Order" (/order/myorder). The process of buying tickets and refunds is handled using database transactions.
The release version 0.9 on GitHub mainly implements the above features. 1 integrates spring Security and uses JWT to authenticate and authorize users.
Certification
The authentication process is as follows: Send a POST request to the/login address, submit a form containing the user name password, the program enters the Jwtloginfilter attemptauthentication method, receives and resolves the user credentials. Then enter the Customerauthenticationprovider authenticate method to compare the received user information with the information in the database, if consistent, Generate a token and enter the Successfulauthentication method of Jwtloginfilter, in which the JWT is generated and the JWT is returned to the front end as the response header.
In subsequent requests, as soon as the JWT is set to the "Authorization" field of the request header to the backend, the backend can parse the header for user information.
Database
The database name is ticketmanagement and there are three tables: customer, Ticket, OrderForm (here, because order is the SQL keyword, the table name order produces a run-time error).
Customer
Ticket
OrderForm:
Follow-up ideas
1.SQL optimization, database operation processing is also relatively rough, in the case of high concurrency operation of the database may have a longer response time and so on. Later, you can improve performance by optimizing SQL. SQL optimization here Bo Master or master is not very good, I hope there are ideas and suggestions of friends can leave a message or contact me to help me.
2. Split the user authentication, authorization and ticketing management services into a micro-service form. Micro-service is the hotspot of the present, which has the advantages of decoupling and distributing. is also the accumulation of their own technology stack.
3. Add the Mail Service feature to enable registration to successfully send mail to the registered mailbox.
github:https://github.com/gene1994/ticketmanagementmy: Kyoccu
"Spring Boot starter" simulation online ticketing system