Springboot Cangqiong takeaway actual combat: 1. Environment construction (nginx startup failure solution + Entity, DTO, VO, POJO difference explanation + nio.charset.Input length = 2 error report solution)

Environment setup

Front-end environment construction

There is a “front-end operating environment” folder in day01 of the information. Extract the “nginx-1.20.2” folder to non-Chinese directory, and then directly click nginx in the folder .exe (it doesn’t matter if it crashes).
Then enter localhost directly in the browser. If the following page appears, it means the front end is started successfully.

Solution to startup failure

If not, the possible reason is that port 80 is occupied.

  1. You can choose to modify port 80 of “nginx.conf” in “conf” under “nginx-1.20.2” and change it to another port
    server{
    listen 80;
    
  2. You can also choose to close applications occupying port 80. After cmd opens the command line, enter the following command
    netstat -ano | findstr 80
    

    Found the following page:

    The last 14469 and so on are the process IDs occupying the port. Then enter

    tasklist | findstr 14468 in the cmd window
    

    Found the following page:

    The explanation is that the nginx service occupies port 80 (I am just doing a demonstration here, so there is no service that actually occupies the port). You can then enter the following command to directly close the process, or you can go to the task manager to close it.

    taskkill /PID 14468
    

Back-end environment construction

There is a “Backend Initial Project” folder in “day01” of the information. Unzip the “sky-takeout” folder and open it in IDEA.

Project structure and sub-module description (including differences between Entity, DTO, VO and POJO)

Serial number Name Description
1 sky-take-out Maven parent project, unified management of dependency versions, Aggregate other submodules
2 sky-common submodules to store public classes, such as tool classes and constant classes , exception classes, etc.
3 sky-pojo submodule, which stores entity classes, VO, DTO, etc.
4 sky-server Sub-module, back-end service, stores configuration files, Controller, Service, Mapper, etc.

Analyze the role of each package of the sky-common module:

Name Description
constant Store related constant classes
context Storage context classes
enumeration Project’s enumeration class storage
exception Storage of custom exception classes
json Classes that handle json conversion
properties Store SpringBoot related configuration property classes
result Encapsulation of return result class
utils Common tool classes

Analyze the role of each package of the sky-pojo module:

Name Description
Entity Entity, usually corresponding to the table in the database
DTO Data transfer object, usually Used to transfer data between various layers in the program, that is, the data from the front end to the back end
VO View object, which is an object provided for the front end to display data. That is, the backend transmits the data to the frontend
POJO Ordinary Java objects, which only have attributes and corresponding getters and setters. The above three are generally POJO objects

Analyze the role of each package of the sky-server module:

Name Description
config Store configuration classes
controller Storage controller classes
interceptor Store interceptor classes
mapper Storage mapper interface
service Storage service class
SkyApplication Startup class

Git initialization

Create a git local repository

Create a git local repository

When Idea appears:


It means the local warehouse is created successfully.

Then start submitting:

Appears in the middle, click commit. (This is just because the project initialization code is not perfect yet, there are errors, and it was checked by git)

Create a git remote repository and push it

Visit https://gitee.com/, create a new warehouse, and copy the URL as a backup.
Then open the remote warehouse management of git, which can be opened from the following two places:

  • The first method
  • The second method

Then paste the url into the following page.

Then click push and find new content in gitee’s warehouse, which means the push is successful.

Table environment construction

There is a “database” folder in “day01” of the data. Use database tools such as Navicat to run the “sky.sql” file in it.
It was found that the new database sky_take_out was added, and the following table was added:

strong>

Serial number Table name Chinese name
1 employee Employee table
2 category Classification table
3 dish Menu List
4 dish_flavor Dish Flavor Table
5 setmeal Package table
6 setmeal_dish Set menu relationship table
7 user User table
8 address_book Address list
9 shopping_cart Shopping cart Table
10 orders Order table
11 order_detail Order detail list

Start backend code

  1. Modify the database connection information of application-dev.yml under the project sub-module sky-server, and replace the user name and password with your own database user name and password.
  2. Check whether the versions of your own jdk and the jdk required by the project are consistent. The project uses java8 and the language level is also 8. Then you need to open the project structure settings and confirm the SDK and language level of “Project” under your project settings, “Language Level” under “Module”, and “SDK” under Platform Settings.
  3. Check whether your own file encoding format is consistent with the project’s file encoding format. This project uses UTF-8, so check whether the file encoding of your project is also UTF-8.
  4. If there are any modifications to the above, you need to rebuild the project and then start the project to see if an error is reported

Startup error java.nio.charset.MalformedInputException: Input length = 2

If started, the following error is reported:

15:33:55.840 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.yaml.snakeyaml.error.YAMLException: java.nio.charset.MalformedInputException: Input length = 2
…
Caused by: java.nio.charset.MalformedInputException: Input length = 2

It means that the file encoding is incorrect. Please note that you need to rebuild the project after modifying the file encoding.