Spring framework learning technology checklist

Pre-basic technology list

1. About environment variables

You must know the role of the "environment variable", and configure the path of the necessary commands to the PATH of the environment variable.

Example – Configuring Java environment variables: http://doc.canglaoshi.org/doc/windows_jdk_eclipse.html

Note: Whether it is the CMD command prompt window or the Terminal window in IntelliJ IDEA, the environment variables are loaded at startup. If you have modified the configuration of the environment variable afterwards, you must reopen the CMD command prompt window , or restart IntelliJ IDEA to apply the new configuration.

2. About the Maven repository

You must know that Maven has a remote warehouse server. When you pom.xmladd dependencies in the Maven project, it will download the required dependency files from the remote warehouse server.

You should configure the remote warehouse server as a domestic server, usually Huawei Cloud or Alibaba Cloud, which can greatly improve the efficiency of downloading dependencies and reduce the risk of data loss when downloading files.

Example: http://doc.canglaoshi.org/doc/idea_install_202010/20201019-IDEA-1-INSTALL.html

Regarding the Maven warehouse server of Huawei Cloud or Alibaba Cloud, you can choose one of them at will. If a certain server is not stable enough for a certain period of time, you should switch to another one.

The relevant files downloaded from the remote warehouse server will appear in your local warehouse. If you are using a Windows operating system, it will be in C:\Users\你登录系统时的用户的用户名\.m2\repositorythis If you are using a Mac operating system, it will be in /Users/你登录系统时的用户的用户名/.m2/repositorythis location by default. You You must clearly know the location of your local warehouse, and you may need to perform certain operations here. For example, when the files in the local warehouse file are damaged, you need to find these files and delete them.

3. Questions about dependency errors

When your Maven project (including Spring Boot project, because it itself is also a Maven project) prompts a dependency error, first of all, you should check whether the code of the dependency is correct. If your dependency is a third-party, you can download it from https ://www.mvnrepository.com to find the correct dependency code, if your dependency is another module defined by yourself, you should check the relevant declarations in the dependent module (such as Artifact Id, Group Id, Version) Is it consistent with adding dependencies.

If the code for your dependencies is correct, you should try all of the following in order:

  1. Close IntelliJ IDEA completely
  2. Delete the local repository folder
  3. Start IntelliJ IDEA and open your project, click the refresh button in the Maven panel

Regarding the second step of the above operation, you can actually delete only some files that are suspected to be problematic, instead of deleting the entire local warehouse. However, the association of dependencies used in the future may be very complicated, and you may not be able to quickly and accurately find the suspected problematic files. file, so from an operational point of view, it is simpler to delete the entire local repository.

If the above steps do not solve your problem, you can also try:

  • Switch the configuration of the remote warehouse server between Huawei Cloud and Alibaba Cloud
    • Sometimes a remote warehouse server may be unstable due to network fluctuations
  • Switch your network connection, such as using China Mobile/Unicom/Telecom mobile phones to provide Internet hotspots, or switch between these 3 operators

4. About exception information

When an exception occurs in your program, a trace report of the exception will be displayed on the console. Usually, the line Caused Bybeginning will prompt the type and key information of the exception. This line of information is very helpful for troubleshooting, please check it carefully.

If there is nesting of exception information, there will be multiple lines Caused By, among which, the information Caused Byprompted is the most accurate and the most reference value! However, if errors involving some external files, such as XML file errors, you may need to use the information Caused Byin to determine the location of the XML file.

5. About the problem that the port is occupied

When you enable a service and prompt that the port is occupied, you can try to modify the configuration in the project to use other ports. If it is not convenient to use other ports, you should terminate the process that occupies the port, and then start your service.

In the Windows operating system, you need to execute the following command in the CMD command prompt window to find out the process ID that occupies the port:

netstat -ano |findstr 端口号

After executing the above command, the ID of the process occupying the port will be prompted, that is, PID, and then execute the following command to terminate the process corresponding to this PID:

taskkill /f /t /im 进程ID

In the Mac OS operating system, you need to execute the following command in the terminal to find out the process ID that occupies the port:

lsof -i :端口号

After executing the above command, the ID of the process occupying the port will be prompted, that is, PID, and then execute the following command to terminate the process corresponding to this PID:

kill -9 进程ID

6. About installing plugins in IntelliJ IDEA

In IntelliJ IDEA, the operation mode of installing plug-ins is fixed. Take the installation of LOMBOK plug-ins as an example, refer to: http://doc.canglaoshi.org/doc/idea_lombok/IDEA-5-PLUGINS-LOMBOK.html

Since the plug-in warehouse server of IntelliJ IDEA is not a domestic server, there may be problems that the plug-in cannot be found, cannot be installed, and the installation speed is extremely slow. You can try again later, or switch your network connection, such as using mobile/ Unicom/Telecom mobile phones provide Internet hotspots, or switch between these 3 operators.

7. About copying external files into your project

If you copy external files (files other than your project, such as files in your teacher's project) to your project, there may be problems that IntelliJ IDEA does not recognize, specifically:

  • The file does exist, but IntelliJ IDEA prompts that there is no such file

When this problem occurs, you can solve it by the following steps:

  1. Delete your project's targetfolder
  2. Right-click on the root-level name of your project and select Reload from diskOptions
  3. BuildClick > in the menu at the top of the windowBuild Project

8. About DML SQL statement

Regarding DML SQL statements, you must be proficient in:

  • Insert 1 record
    • an explicit list of specified fields
  • Insert multiple records
    • There can be multiple record values ​​on the right side of valuesthe keyword
  • Delete records based on specified conditions
  • Delete records without specifying conditions
    • This will delete all records in the table, which is not allowed in development practice
  • Batch delete several records
    • use insyntax
  • Update data in a record based on specified conditions
  • Update records without specifying conditions
    • This will update all records in the table, which is not allowed in development practice
  • Batch update several records
    • use insyntax
  • Use statistics query
    • use count()function
      • It is strongly recommended to use count(*)insteadcount(字段名)
  • Use deduplication query
    • use distinctkeywords
  • Query a record based on specified conditions
    • A list of fields must be specified explicitly
      • Asterisks for field lists are not allowed in development practice
    • If there may be more than one query result, the collation must be explicitly order byspecified
      • If the sorting rules cannot confirm the data of some records, you should specify the second sorting rule, the third sorting rule, etc. on the original basis until all records are sorted by the set rules
    • If the number of records in the query result may be large, it must be explicitly used limitfor paging processing
  • Association table query
    • Understand the use of join// inner join/left joinright join
    • When there are fields with the same name in multiple tables, you need to customize the alias

9. About importing SQL scripts

After logging in to MySQL in the CMD command prompt window, the SQL script can be imported through sourcethe command , for example:

source d:\db.sql

Before performing the import, you should check the contents of the SQL script. You may need to create a database in advance and apply the database before performing the import.

10. About common HTTP response codes

Official document (English version): http://doc.canglaoshi.org/rfc/rfc1945.txt

Official document (Chinese version): http://doc.canglaoshi.org/rfc-cn/RFC1945.txt

Popular description of common HTTP response codes (the solutions to the problems involved in the following can be temporarily skipped before learning the corresponding framework technology):

  • 200: Successful response, it should be noted that this only means that the server has successfully responded to this operation, and does not mean that the business is successful. For example, when trying to log in, if the user name or password is wrong and the login fails, as long as the server responds successfully Yes, the response code is also 200
  • 302: Redirection, after the server processes the request, it will respond with this response code and another target path. Usually, the browser will automatically request a new target path after receiving this response code
  • 400: The request parameter is wrong. For example, the server has set the agreement that "null is not allowed" for a certain request parameter, but the client has not submitted this parameter, or a request parameter must be of numeric type, but the client submitted is a parameter value that cannot be converted to a numeric type
    • When this problem occurs, you should observe the submitted request parameters through breakpoints or piling, and check the server-side constraints on request parameters
      • In the Spring MVC framework, @RequestParamthere is a "not allowed to be null" convention by default
      • In the Spring MVC framework, it will try to automatically convert the request parameters to the parameter types declared on the server side
      • In the Spring MVC framework, after using the Hibernate Validation verification mechanism, there will also be constraints on the request parameters. For specific constraints, please refer to the annotations used
      • The advanced framework based on the above framework has the same effect. For example, the Spring Boot project with added spring-boot-starter-webdependencies uses Spring MVC to receive request parameters, and the Spring Boot project with added spring-boot-starter-validationdependencies uses Hibernate Validation to implement request parameter validation.
  • 401: Unauthorized, usually when you are not logged in, but try to request a resource that must be logged in to allow access
  • 403: Forbidden, usually occurs when you are logged in but do not have access rights, such as when ordinary users try to request resources with administrator rights
    • When this problem occurs, if you use the Spring Security framework, you should check the relevant configuration in the Spring Security configuration class, such as the whitelist path, and check whether you have enabled authorized access. If it is enabled, you should also pass assertion or Observe the permission list of the currently logged-in user by means of piling, and check the permission rules set on the requested resource
  • 404: The requested resource does not exist, usually the wrong URL submitted by the client
    • When this problem occurs, you should check whether the URL submitted by the client is consistent with the URL set by the server to receive the request parameters
    • While ensuring that the URL the client submits the request to is what you expect, on the server side you should:
      • If you are requesting a static resource on the server side, you should check whether the resource exists. In the Spring Boot project, the default static resource folder is, and, note that src/main/resources/staticif you explicitly configure the static resource folder , will override this default
      • If your server side is developed by Spring MVC framework, you should check:
        • Whether the controller has been enabled normally, you can explicitly add a parameterless constructor in the controller class, and output any content in it, when you start the project, you should be able to see the contents of the output statement in the console, if If you can’t see it, it means that the controller has not been created. You need to check whether the component scanning configuration package and controller class are added @Controlleror @RestControllerannotated. If you are using a Spring Boot project, the default component scanning package is specified when creating the project Package name of Group Id and Artifact Id components
        • The request path is obtained by combining the annotation on the controller class @RequestMapping(if it exists) and @RequestMappingother annotations (such as etc.) on the method that handles the request or as a meta-annotation , you should check these 2 annotations@GetMapping
  • 405: The request method is wrong, for example, the server requires the POST method to submit the request, but the client uses the GET method to submit the request
    • When this problem occurs, you should check the request method of the client. If the request is submitted by directly entering the URL in the address bar of the browser, it is a GET method. If it is submitted through an HTML form or other asynchronous methods, unless explicitly used POST method, otherwise it is GET method. In addition, on the server side, you need to check how to configure the request URL. For example, when using it, the @PostMappingclient’s request method must be POST
  • 406: Unacceptable, which usually appears in Spring MVC-based projects. When setting the server-side response method to respond to the body in JSON format, if this is the case, you should check:
    • jackson-databindAre the dependencies added correctly?
    • @EnableWebMvcAre annotations added to the Spring MVC configuration class
  • 500: internal server error, usually because an exception occurred on the server side and has not been explicitly captured
    • e.printStackTrace()When this problem occurs, you should check the exception information of the server-side console. If there is no information, you should check whether the Spring MVC unified exception handling mechanism is used in the project, and the exception information is output by not adding when handling the exception.

11. About char and varchar in MySQL

Compared with the two, charthe storage space occupied is slightly smaller, and the efficiency of storage and reading is slightly higher. Therefore, it should be used first when feasible char.

Usually, if the string length of a field does not change much, the field type can be designed charnot only when the string lengths are exactly the same, of course, if the string lengths may indeed be different, when the characters are read Values ​​should be stripped of extra spaces.

12. About utf8mb4

In the current MySQL version, if utf8encoding is used, it means utf8mb3that a maximum of 3 bytes will be used to represent a character, and utf8mb4a maximum of 4 bytes will be used to represent a character.

utf8mb4There will be more possibilities for using, for example, it can represent some rare characters, emojo expressions, etc. At the same time, because it uses "at most" 4 bytes, if a character only needs 3 bytes to represent, it will only use 3 Bytes will not cause waste of storage space, so it is usually recommended to explicitly specify the encoding of each data table as utf8mb4.

13. About other operations

You should be proficient in the following operations:

  • Install IntelliJ IDEA and configure the remote Maven warehouse server
    • Video tutorial: http://doc.canglaoshi.org/doc/idea_install_202010/20201019-IDEA-1-INSTALL.html
  • Configure the Database view in IntelliJ IDEA
    • Video tutorial: http://doc.canglaoshi.org/doc/idea_database/index.html
  • Install the plugin in IntelliJ IDEA
    • Video tutorial: http://doc.canglaoshi.org/doc/idea_lombok/IDEA-5-PLUGINS-LOMBOK.html
  • Create a Maven Web APP running on Tomcat in IntelliJ IDEA
    • You've probably never done this before
    • Video tutorial: http://doc.canglaoshi.org/doc/idea_tomcat/index.html
  • For other basic operations, such as configuring Git, etc., you can find relevant tutorials at http://doc.canglaoshi.org

14. About the development environment

Regarding your development environment, you should ensure the following:

  • The account you log into the operating system has administrator privileges
    • Otherwise, the installation of some software or the operation of commands will be affected
  • Do you know how to open software or execute commands as an administrator
  • Do you know how to add exceptions in the operating system's firewall settings, or turn off the operating system's firewall
  • Your IntelliJ IDEA is available normally, and the currently recommended version is between v2021.1.3 and v2022.3.1
  • Your IntelliJ IDEA has been configured with Alibaba Cloud or Huawei Cloud as the remote Maven warehouse server, and you have clearly mastered the two remote Maven warehouse servers by changing the settings.xml configuration file
  • Your MySQL or MariaDB is normally available, and the environment variables have been configured, you can execute the mysql command in any path of the command prompt window
  • It is recommended to use the FireFox browser, there is no specific requirement for the FireFox version

Guess you like

Origin blog.csdn.net/gezongbo/article/details/126264186