main mission
Front-end and back-end separation development concept
The development interface refers not to the development of the interface, but the process of developing the controller, mapper, and service
Database Design Specifications
The following stipulations are only for this module. For more comprehensive documents, please refer to "Alibaba Java Development Manual": 5. MySQL database
1. The library name and the application name should be as consistent as possible.
2. Table names and field names must use lowercase letters or numbers, and numbers at the beginning are prohibited.
3. Table names do not use plural nouns
4. The name of the table is best to add "the role of the business name_table". For example, edu_teacher
5. The table must have three fields: id, gmt_create, gmt_modified
Description:
The id must be the primary key, the type is bigint unsigned, it is incremented for a single table, and the step size is 1.
(If using cluster deployment with sub-database and sub-table, the id type is verchar, which is not self-incrementing, and distributed id generator is used in the business.)
The types of gmt_create and gmt_modified are both datetime types. The former means active creation in the present tense, and the latter is past participle. Indicates passive updates.
6. The number of rows in a single table exceeds 5 million rows or the capacity of a single table exceeds 2GB, only sub-database and table-sharding are recommended. Note: If it is expected that the data volume in three years will not reach this level at all, please do not split the database and the table when creating the table.
7. Fields that express the concept of yes or no must be named in the way of is_xxx, and the data type is unsigned tinyint (1 means yes, 0 means no).
Description: If any field is non-negative, it must be unsigned.
Note: Do not add the is prefix to any boolean variable in the POJO class. The database represents the value of yes or no, using the tinyint type, and insisting on the naming method of is_xxx in order to clarify its value meaning and value range.
Positive example: the field name is_deleted expressing tombstone, 1 means deleted, 0 means not deleted.
8. The decimal type is decimal, and the use of float and double is prohibited. Note: When float and double are stored, there is a problem of precision loss, and it is very likely that incorrect results will be obtained when comparing values. If the range of stored data exceeds the range of decimal, it is recommended to split the data into integers and decimals and store them separately.
9. If the length of the stored strings is almost equal, use the char fixed-length string type.
10. varchar is a variable-length string, no storage space is allocated in advance, and the length should not exceed 5000. If the storage length is greater than this value, define the field type as text, separate a table, and use the primary key to correspond to avoid affecting other field indexes. efficiency.
11. The unique index name is uk_field name; the common index name is idx_field name.
Description: uk_ is unique key; idx_ is short for index
12. Foreign keys and cascades must not be used. All foreign key concepts must be resolved at the application layer. Foreign keys and cascading updates are suitable for single-machine low concurrency, but not suitable for distributed and high-concurrency clusters; cascading updates are strong blocking, and there is a risk of database update storms; foreign keys affect the insertion speed of the database.
Create project structure
- Create parent project
- pom type manages version dependencies and puts public dependencies
- Create submodule in parent project
- In submodules you can also create submodules
Project structure
Module description
guli-parent: Online teaching root directory (parent project), manages four sub-modules:
** canal-client: canal database table synchronization module (statistical synchronization data) **
** common: common module parent node **
common-util: Tool module, all modules can depend on it
service-base: the base package of the service service, including the public configuration class of the service service, all service modules depend on it
spring-security: the authentication and authorization module, the service service that requires authentication and authorization Depends on it
** infrastructure: basic service module parent **
api-gateway: api gateway service
** service: api interface service parent **
service-acl: user rights management api interface service (user management, role management and permissions management, etc.)
service-cms: cms api interface service
service-edu: teaching-related api interface service
service-msm: SMS api interface service
service-order: order-related api interface service
service-oss: Alibaba Cloud oss api interface service
service-statistics : Statistical report api interface service
service-ucenter: Member api interface service
service-vod: video on demand api interface service
Develop lecturer management module (backend)
Ready to work
- Create database, create instructor data table
- Build the project structure and configure the pom.xml file
- Create an application configuration file and use the CodeGenerator code generator to automatically generate code
Always set to absolute path
The primary key strategy is written as the type of your primary key, where the primary key type is char type, use ID_WORKER_STR, if it is long type, use ID_WORKER
date type, the date type in the database is datetime, and the date type in the entity class is date
The result generated is as follows
- finall
Date format issue
added in application.properties
#返回json的全局时间格式
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
- Tombstone
- Configure swagger
- Create a common module common, integrate swagger, make all modules accessible,
- The pom file of the module that needs to be imported introduces the public module
- Add an annotation to the startup class and configure the package scan rule @ComponentScan(basePackages = { "com.xuan" })
- Write a configuration class
- 访问 http://localhost:8001/swagger-ui.html
- Create a common module common, integrate swagger, make all modules accessible,
- Unified return data format
- In the project, we will encapsulate the corresponding data into json. Generally, we will unify the data format of all interfaces, so that the front-end operation of the data is more consistent and easy. The basic format our system requires to return is as follows
-
list:
pagination:
no data returned:
failed:
so we define uniform result
- Create an interface to define the return code, create a result class, add dependencies to the service module, and finally modify the return result in the controller
- Paging query
- Configure the paging plugin in MyBatisPlusConfig
- Paging Controller method
- Test in Swagger
- Paging condition query
- Configure the mp paging plugin
- The method of writing the lecturer's paging query interface
- Encapsulate the conditional value into the vo class
- RequestBody: You must use post to submit, use json to transmit data, and encapsulate the json data into the corresponding object
- ResponseBody: The returned data is json data
- Adding and Modifying Instructors
- Add the package handler to the service-base module and create an autofill class
- Add autofill annotations to entity classes
- write controller
- Unified exception handling
- Annotation ControllerAdvice is used with ExceptionHandler
- The common module is introduced into the base module