• mybatis-generator自动生成工具配置


    1.添加插件:pom.xml-->build-->plugins 中添加

    <!-- mybatis generator 自动生成代码插件 -->
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.7</version>
                    <configuration>
                        <configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
                        <overwrite>true</overwrite>
                        <verbose>true</verbose>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>5.1.37</version>
                        </dependency>
                    </dependencies>
                </plugin>

    2.在resources下新建文件夹generator,新建generatorConfig.xml

    <?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>
        <context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat">
    
            <property name="autoDelimitKeywords" value="true"/>
            <property name="beginningDelimiter" value="`"/>
            <property name="endingDelimiter" value="`"/>
    
            <!--覆盖生成XML文件-->
            <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
            <!-- 生成的实体类添加toString()方法 -->
            <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
    
            <!-- 不生成注释 -->
            <commentGenerator>
                <property name="suppressAllComments" value="true"/>
            </commentGenerator>
    
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://localhost:3306/courseimooc"
                            userId="courseimooc"
                            password="courseimooc">
            </jdbcConnection>
    
            <!-- domain类的位置 -->
            <javaModelGenerator targetProject="srcmainjava"
                                targetPackage="com.course.server.domain"/>
    
            <!-- mapper xml的位置 -->
            <sqlMapGenerator targetProject="srcmain
    esources"
                             targetPackage="mapper"/>
    
            <!-- mapper类的位置 -->
            <javaClientGenerator targetProject="srcmainjava"
                                 targetPackage="com.course.server.mapper"
                                 type="XMLMAPPER" />
    
    <!--        <table tableName="test" domainObjectName="Test"/>-->
    <!--        <table tableName="chapter" domainObjectName="Chapter"/>-->
    <!--        <table tableName="section" domainObjectName="Section"/>-->
    <!--        <table tableName="course" domainObjectName="Course"/>-->
    <!--        <table tableName="course_content" domainObjectName="CourseContent"/>-->
    <!--        <table tableName="course_content_file" domainObjectName="CourseContentFile"/>-->
    <!--        <table tableName="teacher" domainObjectName="Teacher"/>-->
    <!--        <table tableName="file" domainObjectName="File"/>-->
    <!--        <table tableName="user" domainObjectName="User"/>-->
    <!--        <table tableName="resource" domainObjectName="Resource"/>-->
    <!--        <table tableName="role" domainObjectName="Role"/>-->
    <!--        <table tableName="role_resource" domainObjectName="RoleResource"/>-->
    <!--        <table tableName="role_user" domainObjectName="RoleUser"/>-->
    <!--        <table tableName="member" domainObjectName="Member"/>-->
    <!--        <table tableName="sms" domainObjectName="Sms"/>-->
            <table tableName="member_course" domainObjectName="MemberCourse"/>
        </context>
    </generatorConfiguration>

    3.创建maven启动命令 mybatis-generator:generator -e

    1.打开idea上方的Edit Configurations
    2.点击+号,找到maven
    3.Name:mybatis-generator(随便起)
    4.working directory:找到对应的项目模块(我这里是建在server模块下)
    5.Command line:mybatis-generator:generate -e
    6.点击OK

    4.运行mybatis-generator

  • 相关阅读:
    Tomcat性能调优
    spring 提供的可扩展的接口和类
    Spring boot 定义exit codes 让你定位问题更加简单
    spring中@Async注解的原理和使用
    SpringCache源码深度解析
    ApplicationContextAware和BeanFactoryAware使用理解
    spring aop中引介拦截器的用法
    提高安全性而在HTTP响应头中可以使用的各种响应头字段
    spring aop中targetSource的理解
    PowerMockito使用PowerMockIgnore注解消除类加载器引入的ClassCastException
  • 原文地址:https://www.cnblogs.com/lpzpp/p/12773802.html
Copyright © 2020-2023  润新知