zoukankan      html  css  js  c++  java
  • eclipse中mybatis generator插件的安装与使用,实现自动生成代码

    git地址:https://github.com/mybatis/generator

    下载后解压:

    选择任意一个版本的jar放到eclipse的features目录下即可

     选择任意一个版本的jar放到eclipse的plugins目录下即可

    重启eclispe

    需要mybatis-generator-core.jar

    <dependency>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-core</artifactId>
    <version>1.3.2</version>
    <scope>test</scope>
    </dependency>

    右键-new,会有MyBatis,在指定项目目录下生成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>
        <!-- oracle lib location -->
        <classPathEntry location="E:ackup
    epositorymysqlmysql-connector-java5.1.40mysql-connector-java-5.1.40.jar" />
        <context id="DB2Tables" targetRuntime="MyBatis3">
            <commentGenerator>
                <property name="suppressAllComments" value="true" />
            </commentGenerator>
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                connectionURL="jdbc:mysql://192.168.1.2:3306/palm_2_0_16" userId="root"
                password="sqj888">
            </jdbcConnection>
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
            
            
            <!-- model package and location -->
            <javaModelGenerator targetPackage="cn.zsmy.entity" targetProject="palmdoctor.codesrcmainjava">
                <property name="enableSubPackages" value="true" />
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
            <!-- mapping package and location -->
            <sqlMapGenerator targetPackage="cn.zsmy.mapper" targetProject="palmdoctor.codesrcmainjava">
                <property name="enableSubPackages" value="true" />
            </sqlMapGenerator>
            <!-- dao package and location -->
            <javaClientGenerator type="XMLMAPPER" targetPackage="cn.zsmy.mapper" targetProject="palmdoctor.codesrcmainjava">
                <property name="enableSubPackages" value="true" />
            </javaClientGenerator>
            
            
            
            <table tableName="tb_hello" domainObjectName="Hello"
                enableCountByExample="false" enableUpdateByExample="false"
                enableDeleteByExample="false" enableSelectByExample="false"
                selectByExampleQueryId="false" />
            
                
        </context>
    </generatorConfiguration>

    已存在generatorConfig.xml就不需要新建了,也可以直接copy的。

     

    没报错就是成功了 

    去掉Mybatis Generator生成的一堆 example

    原文:http://www.cnblogs.com/lyh421/p/5672569.html

    mybatis generator自动生成的代码里老是有一堆example,需要改的时候,generatorConfig.xml文件的配置的方法如下:
     
    <table schema="general" tableName="tb_table_name" domainObjectName="EntityName"
        enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
        enableSelectByExample="false" selectByExampleQueryId="false" >
        <property name="useActualColumnNames" value="true"/>
    </table>
     
    我的修改:
     
     
    运行之后,确实没有了。
  • 相关阅读:
    解决:Could not resolve archetype org.apache.maven.archetypes
    Spring MVC配置MyBatis输出SQL
    Spring集成MyBatis 通用Mapper以及 pagehelper分页插件
    关于SpringMVC或Struts2接受参数接收不到的原因
    配置quartz启动时就执行一次
    ajaxFileUpload进行文件上传时,总是进入error
    spring mvc注入配置文件里的属性
    java中将一个文件夹下所有的文件压缩成一个文件
    flume failed to start agent because dependencies were not found in classpath
    ubuntu不能安装pip unable to install pip in unbuntu
  • 原文地址:https://www.cnblogs.com/shihaiming/p/6252214.html
Copyright © 2011-2022 走看看