mybatis自动生成文件配置记录

记录下mybatis自动生成mapper文件,虽然现在有点过时了,但对于新手来说还是有一定用处的(diss下通过这种文章引流关注的博主)。

比较简单,基本就三步搞定!

1、pom配置

<!--mybatis自动生成代码插件-->
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <configuration>
                        <configurationFile>src/main/resources/mybatis/generatorConfig.xml</configurationFile>
                        <overwrite>true</overwrite> <!--允许覆盖生成的文件-->
                        <verbose>true</verbose> <!--允许移动生成的文件-->
                    </configuration>

                </plugin>

 

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" >
<!-- 配置生成器 -->
<!--具体参数参考:http://www.cnblogs.com/wql025/p/5037860.html-->
<generatorConfiguration>
    <!-- 数据库驱动jar路径 不是必须的,可根据个人情况看是否需要使用,主要是针对自定义的驱动包来使用 -->
    <classPathEntry location="本地mysql驱动jar地址" />
    <context id="DB2Tables" targetRuntime="MyBatis3Simple">
        <!--<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"></plugin>-->


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

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://10.***.***.***:3306/sango_db"
                        userId="root" password="123">
<!--实体,查询模型生成-->
        <javaModelGenerator targetPackage="com.xxx.entity"
                            targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!--生成mapper.xml-->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources" >
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="com/xxx/mapper"
                             targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>

        <table schema="public" tableName="user" domainObjectName="User"/>
        

    </context>
</generatorConfiguration>

3.点击maven插件,生成文件

  如果生成过程中报错,需要根据报错进行解决,如果解决不了可以找我留言!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值