#实用#逆向工程#原生mybatis

mybatis逆向工程

mybatis:
  mapper-locations: classpath:/mapper/**/*.xml
  type-aliases-package: com.example.demo.pojo
  configuration:
    map-underscore-to-camel-case: true
spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/blog?useUnicode=true&characterEncoding=UTF-8
    password: your-password
    username: root
    driver-class-name: com.mysql.jdbc.Driver

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.0.RELEASE</version>
                <configuration>
                    <mainClass>com.example.demo.DemoApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--        Mapper 代码生成插件   -->
            <plugin>
                <!--  mybaits 代码生成插件  -->
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.6</version>

                <configuration>
                    <!--  代码自动生成配置文件路径  -->
                    <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
                    <!--  是否覆盖   -->
                    <overwrite>true</overwrite>
                    <!--  允许移动生成的文件  -->
                    <verbose>true</verbose>
                </configuration>

                <dependencies>
                    <!--  依赖库,生成代码时需要数据库驱动  -->
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.6</version>
                    </dependency>


                </dependencies>
            </plugin>


        </plugins>
    </build>

generatorConfig的配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
    <!-- 放到resources目录下,点击 plugin -> mybatis:generate    -->
    <!-- 记得修改默认的密码    -->
    <context id="mysqlTable" targetRuntime="MyBatis3">
        <plugin type="org.mybatis.generator.plugins.FluentBuilderMethodsPlugin" />
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
        <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" />

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/blog?useUnicode=true&characterEncoding=UTF-8"
                        userId="root"
                        password="422525">
        </jdbcConnection>

        <javaModelGenerator targetPackage="com.lyr.pojo"
                            targetProject="./src/main/java">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="com.lyr.dao"
                         targetProject="./src/main/resources/mapper">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <javaClientGenerator type="MIXEDMAPPER"
                             targetPackage="com.lyr.dao"
                             targetProject="./src/main/java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>

        <table tableName="tbl_article" domainObjectName="Article" >

            <generatedKey column="article_id"  sqlStatement="Mysql"  identity="true" />
        </table>
        <table tableName="tbl_category" domainObjectName="Category" >

            <generatedKey column="category_id"  sqlStatement="Mysql"  identity="true" />
        </table>
        <table tableName="tbl_category_article" domainObjectName="CategoryArticle" >

            <generatedKey column="id"  sqlStatement="Mysql"  identity="true" />
        </table>
        <table tableName="tbl_comment" domainObjectName="Comment" >

            <generatedKey column="comment_id"  sqlStatement="Mysql"  identity="true" />
        </table>
        <table tableName="tbl_user" domainObjectName="User" >

            <generatedKey column="author_id"  sqlStatement="Mysql"  identity="true" />
        </table>
    </context>
</generatorConfiguration>

你可能感兴趣的:(数据库)