最近一直在复习ide生成springboot整合mybatis生成逆向工程的代码,

一、首先是通过Maven添加必须的的jar包以及插件,配置如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.xiaoluo</groupId>
    <artifactId>demao</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demao</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
<!--mybatis-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.2</version>
        </dependency>
<!--mysql-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--测试-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <!--逆向工程所需的插件-->

            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
<!--配置文件的路径 默认resources目录下-->
                    <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
                </configuration>
            </plugin>

        </plugins>
    </build>

</project>

当然啦也要根据自己的实际去配置maven
在配置maven的时候我踩了很多坑,首先就是版本的问题

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

我这里呢是使用2.0.5版本的,如果使用更高版本的话会引起冲突的,当爆红的时候就要去到你本地的maven仓库那里把*

爆红的删除掉咯,

当然我的话直接把整个仓库删除了好几次嘿嘿。
这是我创的demao目录
在这里插入图片描述
2.创建一个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>
    <!-- mysql 连接数据库jar 这里选择自己本地位置 -->
    <classPathEntry location="D:\gentle\mysql-connector-java-5.1.30-bin.jar"/>
    <context id="Mysql" targetRuntime="MyBatis3" defaultModelType="flat">
    <property name="beginningDelimiter" value="`"/>
    <property name="endingDelimiter" value="`"/>
    <property name="javaFileEncoding" value="UTF-8"/>

    <commentGenerator>
        <!--&lt;!&ndash; 是否去除自动生成的注释 true:是 : false:&ndash;&gt;-->
        <property name="suppressAllComments" value="true"/>
    </commentGenerator>
    <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                    connectionURL="jdbc:mysql://localhost:3306/sys"
                    userId="root"
                    password="123">
    </jdbcConnection>
        <!-- 生成实体类的包名和位置 -->
        <javaModelGenerator targetPackage="com.sys.pojo"
                            targetProject="src/main/java">
        </javaModelGenerator>

        <!-- 生成 mapper.xml 映射文件的包名和位置-->
        <sqlMapGenerator targetPackage="mapper"
                         targetProject="src/main/resources">
        </sqlMapGenerator>

        <!-- 生成 mapper 的包名和位置-->
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.sys.mapper"
                             targetProject="src/main/java">
        </javaClientGenerator>

        <!-- 生成表: tableName 表名或视图名 、domainObjectName 实体类名  -->
        <table tableName="sys_user_role" domainObjectName="sys_user_role">
            <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>

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

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

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

        <table tableName="sys_role" domainObjectName="sys_role">
            <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>
        <table tableName="sys_menu" domainObjectName="sys_menu">
            <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>
        <table tableName="sys_login_log" domainObjectName="sys_login_log">
            <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>
        <table tableName="sys_log" domainObjectName="sys_log">
            <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>

        <table tableName="sys_dict" domainObjectName="sys_dict">
            <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>
        <table tableName="sys_dept" domainObjectName="sys_dept">
            <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>
        <table tableName="sys_config" domainObjectName="sys_config">
            <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
        </table>
    </context>

</generatorConfiguration>

3.接下来的话就是运行了
在这里插入图片描述
4.这样的话就是显示运行成功了
在这里插入图片描述
5.目录上已经生成成功
在这里插入图片描述
以上呢就是我在整合和复习mybatis的全过程

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值