• IDEA springboot+maven+mybatis pojo代码自动生成


    首先创建GeneratorMapper.xml文件,让着src目录下,

    <?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>
    <!-- 数据库驱动包位置 -->
    <classPathEntry location="D:Software epositorymysqlmysql-connector-java5.1.43mysql-connector-java-5.1.43.jar" />
    <!--配置table表新校内容体,targetRuntime指定采用Mybatis3的版本-->
    <context id="tables" targetRuntime="MyBatis3">
    <!-- 抑制生成注释,由于生成的注释都是英文的,可以不让它生成 -->
    <commentGenerator>
    <property name="suppressAllComments" value="true" />
    </commentGenerator>

    <!-- 数据库链接URL、用户名、密码 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
    connectionURL="jdbc:mysql://localhost:3306/springdb?characterEncoding=utf8&amp;useSSL=true"
    userId="root" password="123456">
    </jdbcConnection>

    <!-- 生成model类,targetPackage指定model类的包名,targetProject指定生成的model放在哪个工程下面 -->
    <javaModelGenerator targetPackage="com.tl.springboot.pojo"
    targetProject="src/main/java">
    <!-- enableSubPackages:是否让schema作为包的后缀 -->
    <property name="enableSubPackages" value="false" />
    <!-- 清理前后的空格 -->
    <property name="trimStrings" value="false" />
    </javaModelGenerator>

    <!-- 生成Mapper映射XML文件位置 -->
    <sqlMapGenerator targetPackage="com.tl.springboot.mapper"
    targetProject="src/main/java">
    <property name="enableSubPackages" value="false" />
    </sqlMapGenerator>

    <!-- 生成mybatis的mapper接口类文件,targetPackage指定mapper接口类的包名 -->
    <javaClientGenerator type="XMLMAPPER"
    targetPackage="com.tl.springboot.mapper" targetProject="src/main/java">
    <property name="enableSubPackages" value="false" />
    </javaClientGenerator>

    <!-- 要生成哪些表(更改tableName和domainObjectName就可以) -->
    <!-- tableName:要生成的表名
    domainObjectName:生成后的实例名
    enableCountByExample:Count语句中加入where条件查询,默认为true开启
    enableUpdateByExample:Update语句中加入where条件查询,默认为true开启
    enableDeleteByExample:Delete语句中加入where条件查询,默认为true开启
    enableSelectByExample:Select多条语句中加入where条件查询,默认为true开启
    selectByExampleQueryId:Select单个对象语句中加入where条件查询,默认为true开启
    -->
    <table tableName="student" domainObjectName="Student"
    enableCountByExample="false" enableUpdateByExample="false"
    enableDeleteByExample="false" enableSelectByExample="false"
    selectByExampleQueryId="false"
    />
    </context>
    </generatorConfiguration>

    第二步在pom文件中加入插件

     <build>
            <plugins>
                <!--mybatis代码自动生成插件-->
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.6</version>
                    <configuration>
                        <!--配置文件路径-->
                        <configurationFile>GeneratorMapper.xml</configurationFile>
                        <verbose>true</verbose>
                        <overwrite>true</overwrite>
                    </configuration>
                </plugin>
            </plugins>
        </build>

    第三不在IDEA左下角找到maven projects,再找到下载好的mybatis插件,双击运行

    出现如上图表示生成成功

  • 相关阅读:
    Vuex之state、mapState、...mapState、getters、mapGetters、...mapGetters
    Vuex之store的使用
    vue-router的使用
    Flutter之用SharedPreferences实现本地存储
    Flutter之闪屏页的开发
    Flutter之打乱对象数组
    Flutter之解决页面底部黄色条纹的方法
    Vue条件渲染方式的使用
    vue-i18n实现国际化的语言切换用法
    解决v-for报错的方法
  • 原文地址:https://www.cnblogs.com/ling-1991/p/9119643.html
Copyright © 2020-2023  润新知