maven mybitas 生成 类对象

1.新建maven项目

2.pom.xml文件中添加插件

  代码:

        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                 <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>

 也可以  选中pom文件 右键--》添加插件 --》弹出对话框 --》点击select --》 选择mybatis-generator-maven-plugin(先将插件作为依赖加入pom是前提)


<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- MyBatis Generator -->
        <!-- Java接口和实体类 -->
        <targetJavaProject>${basedir}/src/main/java</targetJavaProject>
        <targetMapperPackage>com.jiayou.mybatis.mapper</targetMapperPackage>
        <targetModelPackage>com.jiayou.mybatis.entity</targetModelPackage>
        <!-- XML生成路径 -->
        <targetResourcesProject>${basedir}/src/main/resources</targetResourcesProject>
        <targetXMLPackage>mapper</targetXMLPackage>
        <!-- 编译jdk版本 -->
        <jdk.version>1.6</jdk.version>
        <!-- 依赖版本 -->
        <mapper.version>3.2.2</mapper.version>
        <pagehelper.version>4.0.0</pagehelper.version>

</properties>


<!--通用Mapper -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper</artifactId>
            <version>${mapper.version}</version>
        </dependency>


3.在项目的/src/main/resources(默认目录)的文件目录下加入generateConfig.xml
<?xml version="1.0" encoding="UTF-8"?>

<!-- ~ The MIT License (MIT) ~ ~ Copyright (c) 2014 abel533@gmail.com ~ ~
    Permission is hereby granted, free of charge, to any person obtaining a copy
    ~ of this software and associated documentation files (the "Software"), to
    deal ~ in the Software without restriction, including without limitation
    the rights ~ to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell ~ copies of the Software, and to permit persons to whom the Software
    is ~ furnished to do so, subject to the following conditions: ~ ~ The above
    copyright notice and this permission notice shall be included in ~ all copies
    or substantial portions of the Software. ~ ~ THE SOFTWARE IS PROVIDED "AS
    IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~ IMPLIED, INCLUDING BUT NOT
    LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~ FITNESS FOR A PARTICULAR
    PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~ AUTHORS OR COPYRIGHT
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~ LIABILITY, WHETHER IN
    AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~ OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~ THE SOFTWARE. -->

<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
    <properties resource="dbconfig.properties" />

    <context id="Mysql" targetRuntime="MyBatis3Simple"
        defaultModelType="flat">
        <property name="beginningDelimiter" value="`" />
        <property name="endingDelimiter" value="`" />
        <property name="javaFileEncoding" value="UTF-8" />

        <plugin type="${mapper.plugin}">
            <property name="mappers" value="${mapper.Mapper}" />
        </plugin>

        <jdbcConnection driverClass="${jdbc.driverClass}"
            connectionURL="${jdbcurl.mybatis}" userId="${jdbc.user}" password="${jdbc.password}">
        </jdbcConnection>

        <javaModelGenerator targetPackage="${targetModelPackage}"
            targetProject="${targetJavaProject}" />

        <sqlMapGenerator targetPackage="${targetXMLPackage}"
            targetProject="${targetResourcesProject}" />

        <javaClientGenerator targetPackage="${targetMapperPackage}"
            targetProject="${targetJavaProject}" type="XMLMAPPER" />
<!--             测试 -->
        <!-- <table tableName="t_goods_evaluation">
            <generatedKey column="Id" sqlStatement="Mysql" identity="true" />
        </table> -->

    </context>
</generatorConfiguration>

或者2

            代码:

            <?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>
      <classPathEntry location="E:/.m2/repository/postgresql/postgresql/9.1-901.jdbc4/postgresql-9.1-901.jdbc4.jar" />
    <context id="DB2Tables" targetRuntime="MyBatis3">
      <commentGenerator>
        <property name="suppressAllComments" value="true"/>
      </commentGenerator>
      <jdbcConnection driverClass="org.postgresql.Driver"
            connectionURL="jdbc:postgresql://42.101.00.61:5533/soulagou_vshop"
            userId="*******" password="*****">
        </jdbcConnection>
      <javaTypeResolver>
         <property name="forceBigDecimals" value="false"/>
      </javaTypeResolver>
      
      <javaModelGenerator targetPackage="com.mybatis.model" targetProject="src/main/java">
          <property name="enableSubPackages" value="true"/>
          <property name="trimStrings" value="true"/>
      </javaModelGenerator>
       
      <sqlMapGenerator targetPackage="sqlmap" targetProject="src/main/resources">
           <property name="enableSubPackages" value="true"/>
      </sqlMapGenerator>
       
      <javaClientGenerator type="XMLMAPPER" targetPackage="com.mybatis.mapper" targetProject="src/main/java">
        <property name="enableSubPackages" value="true"/>
      </javaClientGenerator>
      <table  tableName="ITEM" domainObjectName="Item" enableCountByExample="false" enableSelectByExample="false" enableUpdateByExample="false" enableDeleteByExample="false">
       
      </table>
    </context>
      
    </generatorConfiguration>

4:项目 右键--》run as --》 maven bulid --》弹出对话框 --》在goals中输入mybatis-generator:generate 或者 点击select --》选择你的mybatis插件 --》apply --》run


5:选择项目 按 F5 刷新项目 出现生成的代码





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值