primo-generator

Project address: github.com/chenhaoxian…

primo-generator-mybatis-plus-maven-plugin

Automatic code generation plugins, through Maven plugin configuration, one-click generation of a single table for all CRUD operations, speed up your business development

The persistence layer is based on Mybatis-Plus

The main function

  • Single table add delete change check
  • Single table conditional query, paging query
  • Druid-based database monitoring
  • Unified query condition model
  • Unify the Controller layer model

Instructions in one step

Note the points that must be modified:

  • The package name of the parent class is changed to the required package name
  • Data source configuration, connections, accounts, and passwords

Other configuration items can be configured as required.

Plug-in dependencies

<plugin>
    <groupId>wiki.primo.generator</groupId>
    <artifactId>primo-generator-mybatis-plus-maven-plugin</artifactId>
    <version>1.0.0</version> 
    <configuration>
        <! -- Output directory (default java.io. Tmpdir), project path -->
        <outputDir>src/main/java/</outputDir>
        <! -- Overwrite files with the same name (default false) -->
        <fileOverride>true</fileOverride>
        <! -- Add level 2 cache configuration to mapper.xml (default true) -->
        <enableCache>true</enableCache>
        <! -- Developer name -->
        <author>chenhx</author>
        <! -- Enable ActiveRecord mode (default true) -->
        <activeRecord>false</activeRecord>
<! --query.open This configuration data was deleted in version 0.0.5 -->
        <query>
            <! Enable conditional paging query and related class generation -->
            <open>true</open>
        </query>
        <! -- Data source configuration, (** required **) -->
        <dataSource>
            <driverName>com.mysql.jdbc.Driver</driverName>
            <url>JDBC: mysql: / / 127.0.0.1:3306 / love? useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull&amp;serverTimezone=GMT%2B8</url>
            <username>root</username>
            <password>12345678</password>
        </dataSource>
        <strategy>
            <! -- Field generation policy, four types, from the name of the meaning: Nochange (default), underline_to_camel, remove_prefix, remove_prefix_and_camel -->
            <naming>underline_to_camel</naming>
            <! -- table prefix -->
            <tablePrefix> </tablePrefix>
            <! --Entity ID generation policy (default ID_worker) AUTO -- AUTO -->
            <idGenType>auto</idGenType>
            <! -- Custom superclass -->
            <! --<superServiceClass>com.baomidou.base.BaseService</superServiceClass>-->
            <! -- include and exclude All tables in the database are generated by default. -->
            <include>
                <property>user</property>
<! -- <property>table1</property>-->
            </include>
            <! -- Table to exclude -->
            <! --<exclude>-->
            <! --<property>schema_version</property>-->
            <! --</exclude>-->
        </strategy>
        <packageInfo>
            <! Com.baomidou = com.baomidou = com.baomidou
            <parent>wiki.primo.generator.mybatis.plus.springbootdemo</parent>
            <! --service package name (default service)-->
            <service>service</service>
            <! --serviceImpl package name (default service.impl)-->
            <serviceImpl>service.impl</serviceImpl>
            <! Entity package name (default entity)-->
            <entity>entity</entity>
            <! --mapper package name -->
            <mapper>mapper</mapper>
            <! -- XML package name (default mapper.xml)-->
            <xml>mapper.xml</xml>
            <query>query</query>
        </packageInfo>
<! -- Template path configuration item -->
        <template>
            <! -- Define path to controller template -->
            <! --<controller>/template/controller1.java.vm</controller>-->
        </template>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.16</version>
        </dependency>
    </dependencies>
</plugin>
Copy the code

Other necessary configurations for running projects

When you add plug-in dependencies, you are ready to run the code generated by the project.

However, an error will be reported when running the project, which can be resolved after the following steps.

Adding a dependency

Necessary JAR package dependencies, version please control yourself

<! Spring Boot Web dependency -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<! - mybatis - plus depend on -- -- >
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.2.0</version>
</dependency>
<! - druid dependence - >
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.14</version>
</dependency>
<! --MySQL JDBC driver -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>
Copy the code

The second scan Mapper

Add to the @SpringBootApplication annotation’s bootclass

// Step 2: Scan mapper
@mapperscan (" Name of the package where your Mapper interface resides ")
Copy the code

Three MyBati Plus configuration

#mybatis-plus mapper XML file address
mybatis-plus.mapper-locations=classpath*:mapper/*Mapper.xml
##mybatis-plus type-aliases file address
mybatis-plus.type-aliases-package=The entity of the entity class package name (example: wiki. Primo. Generator. Mybatis. Plus, springbootdemo. The entity)
# Hump underline conversion
mybatis-plus.configuration.map-underscore-to-camel-case=true
Global switch of configured cache
mybatis-plus.configuration.cache-enabled=true
# Delay loading switch
mybatis-plus.configuration.lazy-loading-enabled=true
Copy the code

Four other

For data source configuration, Druid monitoring configuration, and other configurations, see the application.properties file under the demo project

If there are other functions, the configuration of the demo project will be updated in time

Using the demonstration

primo-generator-maven-plugin-spring-boot-demo

The Springboot project was demonstrated using primo-generator-Maven-Plugin

As you can see, there are currently no classes under this project

Start adding plug-in dependencies in the project’s POM file (if it’s a submodule, in the submodule’s POM)

I have configured only one table here, user, for generation

<! -- include and exclude All tables in the database are generated by default. -->
<include>
    <property>user</property>
</include>
Copy the code

When the configuration items are configured, it is ready to run.

There are two ways to run the IDEA: (1) IDEA can be run directly by double-clicking in Maven view

(2) You can also run the following command:

mvn -DskipTests=true wiki.primo.generator:primo-generator-mybatis-plus-maven-plugin:code
Copy the code

When the execution is complete, you can see the following code generation

If an error message is displayed, check the required configuration to see whether dependencies and Mapper scanning are added.

Version Update Description

Please use the latest version and upload from 1.0.0 to the central repository

1.0.0

  • Delete the query.open switch to forcibly enable conditional paging query and related class generation
  • Some configuration data for a general extraction, convenient for later extension class
  • Druid Enables the Reset All function on the MANAGEMENT HTML page

0.0.4

  • Page interface of service layer and controller layer, page number and quantity parameters are separated
  • The QueryBo class separates query condition attributes to avoid exceptions caused by consistent database table column names
  • The Service layer adds a paging interface for queries through QueryWrapper
  • The Service layer adds a single data return query interface
  • The entity class generates the toString method
  • Service layer added modify interface
  • Page 500 restrictions lifted
  • The Service layer adds modifying entity interfaces based on a list of conditions
  • Add list query interface to service layer

0.0.3

  • Add add, delete, modify and check operations for controller layer
  • Add automatic generation of resultModels
  • Added automatic generation of ResultCodeEnum
  • Added automatic generation of MybatisPlusConfig
  • Supports configured table generation or excludes table generation code

hundreds

  • Generate Query class, according to the Query criteria paging Query. Support to configure whether to generate paging query methods
<query> <! -- Enable conditional paging query and related class generation --> <open>true</open>
</query>
Copy the code

0.0.1

  • Only single-library full table generation is supported
  • You can set entityColumnConstant to control whether the attribute constant is enabled. This function is enabled by default
  • Automatically add keyword escapes to column names
  • Skip existing files, fileOverride
  • Support single table/full library table generation configuration, include

other

Any questions or other functional requirements, please feel free to ask