Back-end lecturer management module

Back-end lecturer management module

The structure of the back-end project

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-hTdcdNmT-1611036676306) (C:\Users\Wang Dongliang\AppData\Roaming\Typora\typora-user-images\ image-20210118223028941.png)]

[External link image transfer failed. The origin site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-nrWXpye5-1611036676309)(file:///D:/JAVA—SpringBoot%E5%88%86%E5 %B8%83%E5%BC%8F%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98/up%E7%AC%94%E8%AE%B0/day02 /day02%E7%AC%94%E8%AE%B0/day02%E9%A1%B9%E7%9B%AE%E3%80%90%E7%8E%AF%E5%A2%83%E6%90 %AD%E5%BB%BA%E5%92%8C%E8%AE%B2%E5%B8%88%E7%AE%A1%E7%90%86%E6%8E%A5%E5%8F%A3 %E5%BC%80%E5%8F%91%E3%80%91/1%20%E9%A1%B9%E7%9B%AE%E7%8E%AF%E5%A2%83%E6%90 %AD%E5%BB%BA/index_files/592a017b-f501-4359-b92f-8b75875c45f7.png)]

Module description

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-mxxr0vcW-1611036676311) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210118223404736.png)]

Provide unified management of packaging methods and versions

Add the pom type after the node

pom

Delete the content in pom.xml

 <!-- 以下内容删除 -->  <dependencies>  
     <dependency> <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter</artifactId>  </dependency> 
     
     <dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-test</artifactId>  <scope>test</scope>  </dependency>  </dependencies>

Treat unused dependencies

Comments should be made temporarily, otherwise an error will be reported during runtime

MP code generator

The first step is to import dependencies

The second step is to write the code

Need to change

String projectPath = System.getProperty("user.dir");//相对路径可能会出现问题
gc.setOutputDir("D:\\JAVA---SpringBoot分布式项目实战\\guli_parent\\service\\service_edu" + "/src/main/java");



        gc.setIdType(IdType.ID_WORKER_STR); //主键策略,判断类型

        dsc.setUrl("jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8");
        dsc.setPassword("123456");


        pc.setModuleName("eduservice"); //模块名
        //包  com.atguigu.eduservice
        pc.setParent("com.atguigu");


        strategy.setInclude("edu_teacher");//指定表


Simple crud MP has been automatically implemented in mapper and service

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-frMfeg3f-1611036676318) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210118233618546.png)]

Scan the mapper

Mapper is an interface, there is no implementation class, it is handed over to spring for management and assembly

method one

Put it on the startup class

Method Two

Put it on the mapper interface

Method Three

Put in the configuration class

/Add or not

It's the same if you add it or not here

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-gdYJmPDQ-1611036676320) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210118234756787.png)]

Must be added at the beginning of this

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-5VK6PNZH-1611036676322) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210118234840945.png)]

Time display problem

"gmtCreate":"2019-10-30T06:18:46.000+0000"

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-kmrS1cZt-1611036676323) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119000859877.png)]

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-AWkaz6lA-1611036676325) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119000938764.png)]

AthPathVariable

@DeleteMapping("{id}")
public R removeTeacher(@ApiParam(name = "id", value = "讲师ID", required = true)
                       @PathVariable String id) {
    
    

Receive the parameters passed in the path

Integrate swagger

first step

Import dependencies

Second step

Write configuration class

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-5473bZNO-1611036676327) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119003355945.png)]

References between different modules

first step

Reference in pom

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-lYjdw34k-1611036676328) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119003731238.png)]

Second step

Configure package scanning rules (Springboot only scans all packages under this category by default)

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-RvHVLxFN-1611036676329) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119004039827.png)]

Unified result return (Json)

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-lzIo5Xrf-1611036676330) (C:\Users\Wang Dongliang\AppData\Roaming\Typora\typora-user-images\ image-20210119104428012.png)]

Introduced when used, the same as references between different modules

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-rCYqZ0jk-1611036676332) (C:\Users\Wang Dongliang\AppData\Roaming\Typora\typora-user-images\ image-20210119104852552.png)]

Conditional query pagination

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-XeMZdTnt-1611036676333) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119112732867.png)]

RequestBody

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-CpVmu50D-1611036676335) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119113117965.png)]

Among them, requirede=false, indicating that you can enter without passing a value

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-uC0PpGnW-1611036676336) (C:\Users\Wang Dongliang\AppData\Roaming\Typora\typora-user-images\ image-20210119113156697.png)]

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-8W7nxogp-1611036676337) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119113419384.png)]

Solve the problem that the database cannot be found in Chinese

Configure in the configuration file

spring.datasource.url=jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8

Conditional query and auto-fill

One is the attribute name fieldname

One is the field column in the table

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-TTNEAzBA-1611036676338) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119125922060.png)]

Add lecturer

id is automatically created using snowflake algorithm (no need to add)

gmtCreater

gmtModified uses auto-fill (no need to add)

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-T2sPreb7-1611036676339) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119130415586.png)]

Modify lecturer

When experimenting, each must have an initial value

method one

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-JzXVO2uT-1611036676340) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119131047247.png)]

Method Two

The id must be included in the json when modifying

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-8BxfmXrh-1611036676341) (C:\Users\Wang Dongliang\AppData\Roaming\Typora\typora-user-images\ image-20210119131124327.png)]

Unified exception handling

Use: add a class and an annotation

Which uses the unified result return, the introduction is the same as above

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-8UYnS89e-1611036676342) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119133600536.png)]

Solve the problem of introducing duplication

Prevent the introduction of duplication

[External link image transfer failed. The source site may have an anti-hotlinking mechanism. It is recommended to save the image and upload it directly (img-4xRoE7ks-1611036676343) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119133732250.png)]

Dependency pass

[External link image transfer failed. The source site may have an anti-leech link mechanism. It is recommended to save the image and upload it directly (img-RHt0Q0HU-1611036676344) (C:\Users\王东梁\AppData\Roaming\Typora\typora-user-images\ image-20210119134009534.png)]

Guess you like

Origin blog.csdn.net/qq_45783660/article/details/112825937