The most suitable SpringBoot+SSM project for novices "Sky Takeaway" actual combat - (2) Development environment construction

Dark Horse Programmer's latest Java project actual combat "Sky Takeaway", the most suitable SpringBoot+SSM enterprise-level Java project actual combat for novices.

Front-end environment construction

The front-end project runs based on nginx, because the "Kangqiong Takeaway" project focuses on the back-end development, so the dark horse programmers directly provided us with the front-end code part, we only need to build the front-end environment locally and run it, focusing on the back-end Just develop.

  1. Download the front-end engineering resource in the resource post and decompress it:

    image-20230706145045771

  2. Enter \nginx-1.20.2\html\skythe path, you can see the packaged project directory structure as follows:

    image-20230706145210945

  3. Then we need to nginx-1.20.2move the directory to a directory without Chinese in order to start normally! ! !

    image-20230706145641006

  4. Double-click nginx-1.20.2/nginx.exethe file, the window will flash, and then visit the browser address [ http://localhost/ ]:

    image-20230706190918716

  5. At this point, the front-end environment has been built.

Note: The reverse proxy has been configured in the current Nginx configuration file, through which the front-end request can be forwarded to the back-end service.

Back-end environment construction

project structure

The back-end project is built based on maven and developed in modules. The directory structure of the project is as follows:

Use IDEA to import the initial project, the overall structure of the project is as follows:

image-20230707173824880

Description of the role of each module of the project:

serial number name illustrate
1 sky-take-out Maven parent project, unified management of dependency versions, aggregation of other submodules
2 sky-common Sub-module, storing public classes, such as tool classes, constant classes, exception classes, etc.
3 sky-pojo Sub-module, storing entity classes, VO, DTO, etc.
4 sky-server Sub-modules, back-end services, store configuration files, Controller, Service, Mapper, etc.

After understanding the overall structure of the project, let's analyze each of the above sub-modules in detail:

sky-common module

The sky-common module stores some public classes that can be used by other modules:

image-20230707174222358

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

name illustrate
constant Store related constant classes
context storage context class
enumeration Item's enum class storage
exception Store custom exception classes
json Classes that handle json conversion
properties Store SpringBoot related configuration property classes
result Returns the encapsulation of the result class
utils Common tools

sky-pojo module

The sky-pojo module stores some entity, DTO, VO classes:

image-20230707174331434

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

name illustrate
Entity Entities, usually corresponding to tables in the database
DTO Data transfer objects, usually used to transfer data between layers in the program
VO View object, the object provided for the front end to display data
POJO Ordinary Java objects, only properties and corresponding getters and setters

sky-server module

The sky-server module stores configuration files, configuration classes, interceptors, controllers, services, mappers, startup classes, etc.:

image-20230707174415312

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

name illustrate
config Storage configuration class
controller Store the controller class
interceptor store interceptor class
mapper store mapper interface
service store service class
SkyApplication startup class

Git version control

Create a local repository

  1. Click [VCS], [Create Git warehouse]:

    image-20230707174623594

  2. Select the current project and click OK:

    image-20230707174957704

  3. The git submit button appears, and the local warehouse is created successfully:

    image-20230707175044068

Create a remote repository

  1. Visit https://gitee.com/ , create a new warehouse, and improve warehouse information:

    image-20230707175435482

  2. Click Create:

    image-20230707175616876

Push local files to remote warehouse

  1. Add remote warehouse address:

    test

  2. Click the submit button in the IDEA menu bar:

    image-20230707180606108

  3. Select [Files without version management], enter the comments for this submission below, and click [Submit and push] [Submit and push anyway]:

    image-20230707181542000

  4. Click to push:

    image-20230707181724513

  5. After the push is complete, just refresh the remote warehouse:

    image-20230707181817005

Database environment construction

  1. Download the database file, [sky.sql]:

    image-20230707182801960

  2. The database can be created directly through the sql file, so there is no need to create the database in advance, just use SQLYog to import the file and execute it:

    image-20230707182913115

  3. After the execution is complete, a total of 11 tables are created:

    image-20230707183028321

Front-end and back-end joint debugging

The login function has been implemented in the initial project of the backend , and the front-end and back-end joint debugging tests can be performed directly. Implementation idea:

  1. Start the front-end environment:

    image-20230706190918716

  2. Start the backend environment:

    image-20230707193351282

  3. Enter the account password [account: admin; password: 123456] on the front-end page to log in:

    image-20230707193432469

Perfect login function

  1. Open the employee table, modify the plaintext password in the database, and change it to 123456 ciphertext encrypted by MD5 [e10adc3949ba59abbe56e057f20f883e]:

    image-20230707201552385

  2. Modify the code of the user login logic in the EmployeeServiceImpl implementation class, call DigestUtilsthe md5DigestAsHex()method to encrypt the password submitted by the front end with MD5, and then compare it with the password queried from the database:

    public Employee login(EmployeeLoginDTO employeeLoginDTO) {
          
          
      ......
    
      //密码比对
      // 对前端传过来的明文密码进行MD5加密处理
      password = DigestUtils.md5DigestAsHex(password.getBytes());
      if (!password.equals(employee.getPassword())) {
          
          
        //密码错误
        throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);
      }
    
      ......
    }
    

Guess you like

Origin blog.csdn.net/qq_20185737/article/details/131604011