用mybatis generator插件生成pojo,dao,mapper

第一步:在pom文件中添加:

			<plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.7</version>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>8.0.30</version>
                    </dependency>
                </dependencies>
            </plugin>

第二步在resource目录下创建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">
        <!-- 生成的java文件编码 -->
        <property name="javaFileEncoding" value="UTF-8"/>
        <!-- mysql 数据库反引号,oracle为双引号 -->
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>

        <commentGenerator>
            <!-- 是否去除自动生成的注释true:-->
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
        </commentGenerator>

        <!-- 数据库连接 -->
        <jdbcConnection connectionURL="jdbc:mysql://【自己的ip】:3306/【自己的数据库】" driverClass="com.mysql.jdbc.Driver" password="【自己的密码】" userId="【自己的用户名】"/>
        <!-- 生成实体类 -->
        <javaModelGenerator targetPackage="com.cs.xademo.pojo" targetProject="../XaDemo/src/main/java">
            <!-- 是否对model添加 构造函数 -->
            <property name="constructorBased" value="true"/>
            <!-- 是否允许子包,即targetPackage.schemaName.tableName -->
            <property name="enableSubPackages" value="false"/>
            <!-- 建立的Model对象是否 不可改变  即生成的Model对象不会有 setter方法,只有构造方法 -->
            <property name="immutable" value="false"/>
            <property name="trimStrings" value="false"/>
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="mappers/db131Mappers" targetProject="src/main/resources" >
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <!-- dao生成的存放地址 targetProject + targetPackage == 生成文件所在位置  生成的dao接口就在项目的com.dao中-->
        <javaClientGenerator targetPackage="com.cs.xademo.dao.dao131"
                             targetProject="src/main/java" type="XMLMAPPER">
        </javaClientGenerator>

        <table schema="db01" tableName="account"  enableSelectByExample="false" enableDeleteByPrimaryKey="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false"/>
        <table schema="db01" tableName="user"  enableSelectByExample="false" enableDeleteByPrimaryKey="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false"/>
        <table schema="db01" tableName="staffs"  enableSelectByExample="false" enableDeleteByPrimaryKey="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false"/>
    </context>
</generatorConfiguration>

第三步:
点这个运行在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值