[Literacy] How to connect the front-end interface with Java?

foreword

As we all know, java is often used for server development. Common functions such as:

  1. Login operation, used to write account password verification logic.

  2. transfer operation.

    Wait, some privacy operations.

    What about the front end? The front end is mainly used for display, and the logic of the back end is displayed to the user in a friendly manner. Such as.

    When you log in, there is a message that you are logging in.

    image-20220411111455275

Display the loding prompt when the network card is used

image-20220412142232277

and many more. Over time, with more and more ways of interacting with users, many other terminals have appeared, such as PC terminal (QQ), Android terminal (QQ on Android), ios terminal, applet, etc., which are related to users. The interactive end is also the end used for display. .insert image description here

To sum up, it can be concluded that the back-end is mainly for business logic, and the super-complex functional business code is processed in the back-end. The display side is mainly used to interact with the user, and the display code includes front-end, PC side, Android side and so on. These display terminals generally correspond to the same set of backend code. For example: when the computer and the mobile phone play QQ, the information is synchronized.

How do front-end requests reach the back-end?

Just think, what happens when I enter a website in the browser? Is it a browser that stores all the information in the world? Some web games are so fun, can you still play games in a browser with hundreds of megabytes? This is also great. How is it achieved?

Put down four words here: information transmission.
insert image description here

  1. Open browser
  2. The browser at this point is an empty shell with nothing in it.
  3. Enter www.baidu.com
  4. At this point, the browser will pull the html code from the Baidu server. The code pulling here generally includes html, js, css, img and other files.
  5. After the pull is complete. The browser parses and displays these codes.
  6. After the display is completed, the Baidu box will be displayed
  7. Users can enter what they want to search for.
  8. The browser receives the content that the user wants to search, and goes to the Baidu server to pull the corresponding information.
  9. The Baidu server returns the searched content and displays it in the browser.

How does the front end send requests?

The specific loading ideas are explained above, and the above ideas can be mapped to our html code and java code. The part of entering the domain name does not require developers to develop. What developers need to focus on is how to interact with the server when the page is loaded.

ajax, a tag, form form, img tag and so on. Every request is captured by the browser's debugging tools.

insert image description here

Most of the above pictures are html requests, but in general, the interface path of our backend java is

  • http://localhost:8080/system/user/login
  • http://localhost:8080/system/student/getUserInfo

and many more. In general, the interface path of the backend consists of 4 parts.

  1. ip+port . Address information for the labeling service. Generally, the local is localhost. The default port of tomcat is 8080, and the port can be modified by yourself.
  2. Project name prefix . Like the above system. This can be defined by yourself. If it is the student management system, it can be done studentSystem; the teacher management system is teacherSystem.
  3. module name . It is divided into user module, login module, teacher management module, student management module, library management module and so on. Each module here generally corresponds to one Controller. such as UserController、StudentController、BookControllerwait
  4. method name . This will correspond to the role of each method, such as login、getUserInfo、updateUser、deleteUserand so on.

How to understand service?

insert image description here

First understand the port, the port can be considered as the entrance and exit of the communication between the computer and the outside world. Macroscopically, it can be understood as usb port, network cable port, etc. Microscopically, the computer has many ports, ranging from 0 to 65535. After each service is started, it must listen to a port. When there is information incoming, the information on this port will be parsed. (Of course, the structure inside will be more complicated. For primary development, it can be understood in this way for the time being). Common ports are tomcat:8080, nginx:80, mysql:3306 , etc.

As shown in the figure below, after tomcat starts, it will listen on port 8080. When there is information input on port 8080 of the computer, it will be parsed. Therefore, the browser needs to add port 8080 when entering information. For example: http://localhost:8080/

image-20220412142010033

Guess you like

Origin blog.csdn.net/qq_30285985/article/details/124259846