超级简单的通用mapper (MavenWeb工程)

超级简单的通用mapper (MavenWeb工程)

前提是ssm整合完成才能使用

1、在pom中引入插件和jar

在build标签中引入

 <!--mybais逆向工程的插件-->
        <plugin>
          <groupId>org.mybatis.generator</groupId>
          <artifactId>mybatis-generator-maven-plugin</artifactId>
          <version>1.3.5</version>
          <configuration>
            <!-- 是否覆盖 -->
            <overwrite>true</overwrite>
            <!--允许移动生成的文件 -->
            <verbose>true</verbose>
            <!-- 自动生成的配置,${basedir}表示项目根目录 ,configurationFile默认在resource目录下-->
            <!--<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>-->
          </configuration>
          <dependencies>
            <!--内部依赖,只为当前插件服务-->
            <dependency>
              <groupId>mysql</groupId>
              <artifactId>mysql-connector-java</artifactId>
              <version>5.1.14</version>
            </dependency>
          </dependencies>
        </plugin>

在resources文件夹下创建一个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>
<!--这个路径就是你maven仓库中的mysql的jar包路径 直接复制过来就行-->
    <classPathEntry location="A:\\B\\java\\maven\\apache-maven-3.6.3-1\\mysql\\mysql-connector-java\\5.1.14\\mysql-connector-java-5.1.14.jar"/>
    <context id="mybatisGenerator" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:是 : false:-->
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!--数据库连接的信息(数据源):驱动类、连接地址、用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/114project?characterEncoding=utf8&amp;useSSL=true"
                        userId="root"
                        password="root">
        </jdbcConnection>

        <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
            NUMERIC 类型解析为java.math.BigDecimal -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <!-- targetProject:生成PO类的位置 -->
        <javaModelGenerator targetPackage="com.ssm.entity"
                            targetProject=".\src\main\java">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
            <!-- 从数据库返回的值被清理前后的空格 -->
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!-- targetProject:mapper映射文件生成的位置 -->
        <sqlMapGenerator targetPackage="com.ssm.mapper"
                         targetProject=".\src\main\resources">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
        </sqlMapGenerator>
        <!-- targetPackage:mapper接口生成的位置 -->
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.ssm.mapper"
                             targetProject=".\src\main\java">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
        </javaClientGenerator>
        <!-- 指定数据库表  简单的增删改查以及选择修改  选择新增-->
        <!-- tableName 写的是你的数据库字段  domainObjectName写的是你想生成对应实体的名称--?
        <table tableName="tab_emp" domainObjectName="TabEmployee"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false" ></table>
        <table tableName="tab_department" domainObjectName="TabDepartment"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="tab_role" domainObjectName="TabRole"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false"></table>
        <table tableName="tab_account"
               domainObjectName="TabAccount"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false"></table>


    </context>
</generatorConfiguration>

最后 双击 Plugins插件下的mybatis-generator下的mybatis-generator:generate

在这里插入图片描述

等待完成

在这里插入图片描述

接下来就可以直接使用了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值