preface

Today we take a springboot project (front and back end is not separated), based on Springboot, Mybatis, layUI implementation

Basic project structure

  1. The first class suffix named SystemApplication is the start class of the project, and its code form is basically as follows:

  • The annotation one declares it to be a Springboot project
  • Note 2 declares the location of its persistent layer scan
  1. Application. Properties is the configuration file that completes the basic configuration of the database and some projects. Some basic configurations of the project are as follows:
# app name
spring.application.name=scientific_research_management_system
# Application service WEB access port
server.port=8085
# database driver:
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# data source name
spring.datasource.name=defaultDataSource
mybatis.mapper-locations=classpath:mappers/*xml
Database connection address
spring.datasource.url=JDBC: mysql: / / 0.0.0.0:3306 / jiangsustore? serverTimezone=UTC
Username & password:
spring.datasource.username=XXX
spring.datasource.password=XXX
# THYMELEAF (ThymeleafAutoConfiguration)
# Enable template caching (default: true)
spring.thymeleaf.cache=true
Check if the template exists before rendering
spring.thymeleaf.check-template=true
# Check that the template is in the correct position (default :true)
spring.thymeleaf.check-template-location=true
# Content-type value (default: text/ HTML)
spring.thymeleaf.content-type=text/html
# Enable MVC Thymeleaf view parsing (default: true)
spring.thymeleaf.enabled=true
# template encoding
spring.thymeleaf.encoding=UTF-8
# Comma-separated list of view names to be excluded from parsing
spring.thymeleaf.excluded-view-names=
The template pattern to be applied to the template. See also StandardTemplate-ModeHandlers(default: HTML5)
spring.thymeleaf.mode=HTML5
# prefix added to the view name when building the URL (default: classpath:/templates/)
# suffix added to view name when building URL (default:.html)
spring.thymeleaf.suffix=.html
# log output
logging.level.root=warn
# log level
logging.level.com.xie.scientific_research_management_system.persistence=trace
# Log output
logging.pattern.console=%p%m%n
# prefix added to the view name when building the URL (default: classpath:/templates/)
spring.thymeleaf.prefix=classpath:/templates/
# specify entity directory of Mybatis

mybatis.type-aliases-package=com.xie.scientific_research_management_system.domain
Copy the code
  1. The Domain layer, also known as the entity layer, generally corresponds to the data types in the database

  1. The Persistent layer, also known as the Dao layer, encapsulates database operations and adds, removes, changes, and checks data. Because the Mybatis persistence layer framework is used in the project, there is no need to write code for database connections and operations. It corresponds to the Mappers layer in Resources, for example, The StudentAccountMapper function getAccountByStudent_idAndPassword() in the persistence layer obtains user information from the passed parameter.

It is implemented in an.xml file:

Mybatis official document

  1. Service layer: it realizes the logical application design of business modules, which is built on the persistence layer to deal with specific transaction logic. A good design can effectively reduce the amount of code of the project.

  2. Controller layer: responsible for the control of the flow of specific business modules, and its implementation of specific transactions is to directly call the interface of the Service layer.

  1. The mappers layer mentioned above, the static layer and the templates layer are the view view layer, where static stores static resources such as CSS files, images, fonts, videos, audio, etc. In addition, the index.html file in static is the initial page of the project and will be accessed after running the project. The structure in the Templates layer is project-specific.

Afterword.

For details on how to implement the separation of the front and back ends of the SpringBoot project, please refer to these two articles:

  • The implementation of the back end in the separation of the front and back ends
  • The realization of front end project in front end separation project