GULI PART.2

the second part

Lecturer Management Module

1. Create a database

error2 error when importing
导入数据库文件 guli.sql (最好使用工具导入,工具会自动识别字符,若手动命令行source命令导入,注意error2错误)

error2错误解决方案:使用命令行dos  使用CD命令到sql文件的文件夹下 使用  source ./guli.sql命令即可。

Note that its character set uses utf8mb3, which is an alias for a certain version of utf-8. I don’t know if this will affect subsequent operations, so I uninstalled it at the beginning of this article.

Target design specifications
https://max.book118.com/html/2022/0617/5300333334004242.shtm

2. Project structure

先创建父工程
父工程的作用:pom类型  管理依赖版本和存放公共依赖
然后在父工程下创建子模块,子模块下创建更小的模块

2.1. Engineering structure

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-3vxJvkgi-1690788312460)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806150859675.png)]

Project description:

guli-parent:在线教学根目录(父工程)管理四个子模块
	canal-client:canal数据库同步模块(统计同步数据)
	common:公共模块父节点
		common-util:工具类模块,所有模块都可以依赖于它
		service-base:service服务的base包,包含service服务的公共配置类,所有service的模块都依赖于它
		spring-security:认证与授权模块,需要认证授权的service服务依赖于它
		
	infrastructure:基础服务模块父节点
		api-gateway:api网关服务
	
	service:api接口服务父节点
		service-aci:用户权限管理api接口服务(用户管理、角色管理和权限管理等)
		service-cms:cms api接口服务
		service-edu:教学相关api接口服务
		service-msm:短信api接口服务
		service-order:订单相关api接口服务
		service-oss:阿里云oss api接口服务
		service-statistics:统计报表api接口服务
		service-ucenter:会员api接口服务
		service-vod:视频点播api接口服务

3. Create a parent project

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-AnD1kjl4-1690788312465)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806151916043.png)]

The video uses springBoot2.2.1 version. Here I will directly choose the current stable version 2.7.2 (pay attention to third-party component compatibility issues)

Document time: 2022-8-6 15:20

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-CMrIv7s3-1690788312470)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806152001704.png)]

Creation completed

After the creation is completed, if you find that the file name is displayed in red without any error, please try git submission.

After creation, add:

<artifactId>guli_parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
加入下面这一句
<packaging>pom</packaging>

<name>guli</name>
<description>guli</description>

Delete everything within the dependencies tag and its subtags

Replace the properties tag with the following

<properties>
        <java.version>1.8</java.version>
        <oes.version>0.0.1-SNAPSHOT</oes.version>
        <mybatis-plus.version>3.5.1</mybatis-plus.version>
        <velocity.version>2.2</velocity.version>
        <swagger.version>2.9.2</swagger.version>
        <jodatime.version>2.10.1</jodatime.version>
        <poi.version>3.17</poi.version>
        <easyexcel.version>2.1.1</easyexcel.version>
        <commons-fileupload.version>1.3.1</commons-fileupload.version>
        <commons-io.version>2.6</commons-io.version>
        <httpclient.version>4.5.1</httpclient.version>
        <jwt.version>0.7.0</jwt.version>
        <aliyun-java-sdk-core.version>4.3.3</aliyun-java-sdk-core.version>
        <aliyun-sdk-oss.version>3.1.0</aliyun-sdk-oss.version>
        <aliyun-java-sdk-vod.version>2.15.2</aliyun-java-sdk-vod.version>
        <aliyun-java-vod-upload.version>1.4.11</aliyun-java-vod-upload.version>
        <aliyun-sdk-vod-upload.version>1.4.11</aliyun-sdk-vod-upload.version>
        <fastjson.version>1.2.28</fastjson.version>
        <gson.version>2.8.2</gson.version>
        <json.version>20170516</json.version>
        <commons-dbutils.version>1.7</commons-dbutils.version>
        <canal.client.version>1.1.0</canal.client.version>
        <docker.image.prefix>zx</docker.image.prefix>
        <cloud-alibaba.version>0.2.2.RELEASE</cloud-alibaba.version>
        <wxpay.version>0.0.3</wxpay.version>
        <common-pool2.version>2.6.0</common-pool2.version>
    </properties>

Add tags

How to check your current spring version and select the corresponding dependency versions of other tools

1、https://blog.csdn.net/qq_42055933/article/details/125694893

2、官网查看reference Doc
https://spring.io/projects/spring-boot#learn

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-BbPAb95p-1690788312475)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806165019527.png)]

视频使用的springCloud版本是Hoxton,我们查看官网后可以发现Hoxton版本支持的SpringBoot的版本为
2.2.x, 2.3.x (Starting with SR5)
所以我们还是跟着项目的2.2.1版本为好,
如果要使用目前的2.7.2版本,我们需要将SpringCloud的版本设置为2021.0.x aka Jubilee
主要支持如下图:
https://spring.io/projects/spring-cloud

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-e1VZRpEH-1690788312480)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806160623363.png)]

<dependencyManagement>
        <dependencies>
            <!--Spring Cloud-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>${cloud-alibaba.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--mybatis-plus 持久层-->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>${mybatis-plus.version}</version>
            </dependency>
            <!-- mybatis-plus generator -->
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-generator</artifactId>
                <version>${mybatis-plus.version}</version>
            </dependency>
            <!-- velocity 模板引擎, Mybatis Plus 代码生成器需要 -->
            <dependency>
                <groupId>org.apache.velocity</groupId>
                <artifactId>velocity-engine-core</artifactId>
                <version>${velocity.version}</version>
            </dependency>

            <!--swagger-->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>${swagger.version}</version>
            </dependency>
            <!--swagger ui-->
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${swagger.version}</version>
            </dependency>

            <!--日期时间工具-->
            <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
                <version>${jodatime.version}</version>
            </dependency>

            <!--xls-->
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>${poi.version}</version>
            </dependency>
            <!--xlsx-->
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi-ooxml</artifactId>
                <version>${poi.version}</version>
            </dependency>
            <!--阿里巴巴的easy excel工具-->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>easyexcel</artifactId>
                <version>${easyexcel.version}</version>
            </dependency>

            <!--文件上传-->
            <dependency>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
                <version>${commons-fileupload.version}</version>
            </dependency>

            <!--commons-io-->
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>${commons-io.version}</version>
            </dependency>

            <!--httpclient-->
            <dependency>
                <groupId>org.apache.httpcomponents</groupId>
                <artifactId>httpclient</artifactId>
                <version>${httpclient.version}</version>
            </dependency>

            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>${gson.version}</version>
            </dependency>

            <!-- JWT -->
            <dependency>
                <groupId>io.jsonwebtoken</groupId>
                <artifactId>jjwt</artifactId>
                <version>${jwt.version}</version>
            </dependency>

            <!--aliyun-->
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-core</artifactId>
                <version>${aliyun-java-sdk-core.version}</version>
            </dependency>
            <dependency>
                <groupId>com.aliyun.oss</groupId>
                <artifactId>aliyun-sdk-oss</artifactId>
                <version>${aliyun-sdk-oss.version}</version>
            </dependency>
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-vod</artifactId>
                <version>${aliyun-java-sdk-vod.version}</version>
            </dependency>
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-vod-upload</artifactId>
                <version>${aliyun-java-vod-upload.version}</version>
            </dependency>
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-sdk-vod-upload</artifactId>
                <version>${aliyun-sdk-vod-upload.version}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>${fastjson.version}</version>
            </dependency>
            <dependency>
                <groupId>org.json</groupId>
                <artifactId>json</artifactId>
                <version>${json.version}</version>
            </dependency>

            <dependency>
                <groupId>commons-dbutils</groupId>
                <artifactId>commons-dbutils</artifactId>
                <version>${commons-dbutils.version}</version>
            </dependency>
            <!--阿里巴巴canal-->
            <dependency>
                <groupId>com.alibaba.otter</groupId>
                <artifactId>canal.client</artifactId>
                <version>${canal.client.version}</version>
            </dependency>
            <!--微信支付接口-->
            <dependency>
                <groupId>com.github.wxpay</groupId>
                <artifactId>wxpay-sdk</artifactId>
                <version>${wxpay.version}</version>
            </dependency>

            <!-- spring2.X集成redis所需common-pool2-->
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-pool2</artifactId>
                <version>${commons-pool2.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

Delete the src directory of the parent project

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-JksSYf10-1690788312485)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806153906463.png)]

4. Initialize submodule

service submodule

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-yyH6O7fk-1690788312489)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806162139978.png)]

modle chooses to create a new Maven project

Note that the maven project chosen here is not the spring project. Although spring is also a maven project, the pom file needs to be modified after creation, so it is not recommended to modify the pom dependencies.

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-AZkN6vq8-1690788312494)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806165207476.png)]

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-W5T8GVTS-1690788312499)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806162249414.png)]

com.guli

After creation, we just declared the module version in the parent module and did not use dependencies. We need to use these in child components to depend on

<parent>
        <groupId>com.guli</groupId>
        <artifactId>guli_parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
</parent>
注意:要记得在子模块中声明父模块是谁

在子模块中使用依赖:
 <dependencies>
     注释掉前四个,后面才会用
        <!-- 引入service_base -->
<!--        <dependency>-->
<!--            <groupId>com.zh.oes</groupId>-->
<!--            <artifactId>service_base</artifactId>-->
<!--            <version>0.0.1-SNAPSHOT</version>-->
<!--        </dependency>-->
        <!--  ribbon依赖  -->
<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>-->
<!--        </dependency>-->
<!--        &lt;!&ndash; hystrix依赖,主要是用 @HystrixCommand  &ndash;&gt;-->
<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>-->
<!--        </dependency>-->
<!--        &lt;!&ndash; 服务注册 &ndash;&gt;-->
<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
<!--        </dependency>-->
<!--        &lt;!&ndash; 服务调用 &ndash;&gt;-->
<!--        <dependency>-->
<!--            <groupId>org.springframework.cloud</groupId>-->
<!--            <artifactId>spring-cloud-starter-openfeign</artifactId>-->
<!--        </dependency>-->
        <!-- spring boot web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- mybatis-plus -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
        </dependency>
        <!-- mybatis-plus代码生成器 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
        </dependency>
        <!--  velocity 模板引擎, Mybatis Plus 代码生成器需要  -->
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
        </dependency>
        <!-- mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!-- swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency>
        <!-- lombok用来简化实体类:需要安装lombok插件 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <!-- 文件上传 -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
        </dependency>
        <!-- gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
        </dependency>
        <!-- 单元测试 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
    </dependencies>

After adding

Remember to click Refresh on Maven in the upper right corner and re-enter the dependent versions.

service-edu submodule

After that, we will delete the src in the service and prepare to create the first instructor-managed module service-edu.

Need to make sure it is under service

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-LyssZ5f7-1690788312503)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806171938576.png)]

Then select the parent object

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-snd1q2IS-1690788312508)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806172332273.png)]

To confirm whether there are any redundant ones in the pom file of guli_parent, delete them.

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-QDVeKXnA-1690788312512)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806172035523.png)]

Due to improper operation, the service project may be created multiple times, and IDEA will think that the POM file was not completely deleted when deleted (because the project name is the same), so it will ignore the POM file, as shown in the figure:

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-CGPNFrXk-1690788312517)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806172806639.png)]

we need to

点击File-》Settings-》Build,Execution…-》Build Tools-》Maven-》Ignored Files 。将右边选中内容取消勾选然后Apply
重启项目即可

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-i40T9ZkY-1690788312522)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806172901090.png)]

Create application.properties file in service_edu project

Then write in the configuration file:

#服务端口
server.port=8001
#服务名称
spring.application.name=service-edu

#环境设置:dev、test、prod(生产)
spring.profiles.active=dev

#mysql数据库连接
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/guli?serverTimezone=GMT
spring.datasource.username=root
spring.datasource.password=li1473606768

#mybatis日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

Write controller, service, mapper

5. Code generator

1. Introduce dependencies

(Already introduced in the service.pom file)

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-X1pCTlDS-1690788312527)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806173903785.png)]

注意自己的版本与mybatis-plus中的差异:https://baomidou.com/pages/779a6e/

For example, my MP here is 3.5.1

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-4vBDdgx4-1690788312531)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806174320718.png)]

According to the prompts on the official website, we need to install a new dependency

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-generator</artifactId>
    <version>3.5.1</version>
</dependency>

Since our MP (mybatis-plus) is version 3.5.1, we need to read the official documentation to configure it

There is a big difference between versions 3.4 and 3.5

https://baomidou.com/pages/779a6e/#%E5%AE%89%E8%A3%85

Then we need to write the configuration method that mybatis has prepared for us in a method that can be started by ourselves (similar to the main method or @test)

Here we choose @Test to implement, create a new file under the test file, and then write the following content in it:

package testUtils;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.po.LikeTable;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;
import org.junit.Test;

import java.util.Collections;

/**
 * className: CodeGenerator<br/>
 * author: MacieSerenity <br/>
 * date: 2022-08-06 17:40
 **/
public class CodeGenerator {
    
    
    /**
     * 全局配置
     */
    public static String DB_USER="root";
    public static String DB_PASSWORD="li1473606768";
    public static String DB_URL="jdbc:mysql://127.0.0.1:3306/guli?serverTimezone=GMT";

    /**
     * 数据源配置 <br/>
     * 报Communications link failure错误的,在url 后面加上 &useSSL=false,
     */
    public static String PROJECT_DIR=System.getProperty("user.dir");
    public static String OUT_PUT_DIR="/src/main/java";
    public static String AUTHOR="MacieSerenity";
    public static String DATE_FORMAT="yyyy-MM-dd HH:mm:ss";

    /**
     * 包配置
     */
    public static String PARENT_PACKAGE_NAME="com.edu";
    public static String PARENT_MODULE_NAME="edu_service";
    public static String ENTITY_PACKAGE_NAME="entity";
    public static String SERVICE_PACKAGE_NAME="service";
    public static String SERVICE_IMPL_PACKAGE_NAME="service.impl";
    public static String MAPPER_PACKAGE_NAME="mapper";
    public static String XML_FOLDER_NAME="";
    public static String CONTROLLER_PACKAGE_NAME="controller";
    public static String OTHER_CONFIG="";
    public static String PATH_INFO="";

    /**
     * 策略配置
     */
    public static String TABLE_PREFIX="edu_";
    @Test
    public void gennerator(){
    
    

        //数据源配置
        DataSourceConfig.Builder dataSourceConfig=new DataSourceConfig.Builder(DB_URL,DB_USER,DB_PASSWORD)
                //数据库查询
                .dbQuery(new MySqlQuery())
                //数据库类型转换器
                .typeConvert(new MySqlTypeConvert())
                //数据库关键字处理器
                .keyWordsHandler(new MySqlKeyWordsHandler());

        //快速生成器
        FastAutoGenerator.create(dataSourceConfig)
                //全局配置
                .globalConfig(builder -> {
    
    
                    //重新生成文件时是否覆盖
                    builder.fileOverride()
                            //输出文件夹的位置
                            .outputDir(PROJECT_DIR+OUT_PUT_DIR)
                            //作者
                            .author(AUTHOR)
                            .enableKotlin()
                            .enableSwagger()
                            .dateType(DateType.TIME_PACK)
                            .commentDate(DATE_FORMAT);
                })
                .packageConfig(builder -> {
    
    
                    //父包名 默认值:com.baomidou
                    builder.parent(PARENT_PACKAGE_NAME)
                            //父包模块名
                            .moduleName(PARENT_MODULE_NAME)
                            //Entity 包名 默认值:entity
                            .entity(ENTITY_PACKAGE_NAME)
                            //Service 包名 默认值:service
                            .service(SERVICE_PACKAGE_NAME)
                            //Service Impl 包名 	默认值:service.impl
                            .serviceImpl(SERVICE_IMPL_PACKAGE_NAME)
                            //Mapper 包名 默认值:mapper
                            .mapper(MAPPER_PACKAGE_NAME)
                            //Mapper XML 包名 默认值:mapper.xml
                            //.xml(XML_FOLDER_NAME)
                            //Controller 包名  默认值:controller
                            .controller(CONTROLLER_PACKAGE_NAME)
                            //自定义文件包名,输出自定义文件时所用到的包名
                            //.other(OTHER_CONFIG)
                            //路径配置信息
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "D://"))
                            .build();
                })
                //策略配置
                .strategyConfig(builder -> {
    
    
                            //开启大写命名
                     builder.enableCapitalMode()
                            //开启跳过视图
                            .enableSkipView()
                            //禁用 sql 过滤
                            .disableSqlFilter()
                            //模糊表匹配(sql 过滤)
                            .likeTable(new LikeTable("USER"))
                            //增加表匹配(内存过滤)
                            .addInclude("edu_teacher")
                            //增加过滤表前缀,指定后,在生成文件时,
                             // 模板会自动截取掉前缀字符,如表名为sys_user,
                             // 指定前缀为sys_,生成实体是自动识别生成为user
                            .addTablePrefix(TABLE_PREFIX);
                    //增加过滤字段后缀
                    //.addFieldSuffix("_flag")
                }).execute();
    }
}

6. Configure Controller

After the class is automatically generated, change the original @Controller annotation to @RestController

[External link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-3EqA0jFl-1690788312536)(%E8%B0%B7%E7%B2%92%E5%AD%A6% E9%99%A2-%E7%AC%AC%E4%BA%8C%E9%83%A8%E5%88%86.assets/image-20220806200735057.png)]

おすすめ

転載: blog.csdn.net/weixin_44673253/article/details/132023367