zoukankan      html  css  js  c++  java
  • Mybatis Generator

    安装插件

    步骤:help -- Eclipse Marketplace

    配置

    SqlServer

    新建配置文件 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>
    	<!--配置 sqlserver jar包路径 -->
    	<classPathEntry
    		location="E://cps-service//lib//sqljdbc42.jar" />
    
    	<context id="bingniterId" targetRuntime="MyBatis3">
    
    		<!--<commentGenerator> <!– 去除自动生成的注释 –> <property name="suppressAllComments" 
    			value="true" /> </commentGenerator> -->
    		<!-- 是否生成注释 去除自动生成的注释 -->
    		<commentGenerator>
    			<property name="suppressDate" value="true" />
    
    			<property name="suppressAllComments" value="true" />
    		</commentGenerator>
    		<!-- 数据库连接配置 -->
    		<jdbcConnection
    			driverClass="com.microsoft.sqlserver.jdbc.SQLServerDriver"
    			connectionURL="jdbc:sqlserver://10.1.10.99:1433;DatabaseName=bingniter"
    			userId="sa" password="!QAZ2wsx" />
    
    		<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制 -->
    		<javaTypeResolver>
    			<property name="forceBigDecimals" value="false" />
    		</javaTypeResolver>
    
    		<!--配置生成的实体包 targetPackage:实体类包路径,默认存放在src目录下; targetProject:目标工程名 -->
    		<javaModelGenerator
    			targetPackage="com.bingniter.entity" targetProject="项目名字 或者 src/main/java" />
    
    		<!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
    		<sqlMapGenerator targetPackage="com.bingniter.mapper"
    			targetProject="learn" />
    		<!--生成Dao类存放位置 -->
    		<javaClientGenerator type="XMLMAPPER"
    			targetPackage="com.bingniter.dao" targetProject="项目名字 或者 src/main/java">
    			<property name="enableSubPackages" value="true" />
    		</javaClientGenerator>
    		<!--生成对应表及类名 -->
    		<!-- 配置表 schema:不用填写 tableName: 表名 enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId: 
    			去除自动生成的例子 -->
    		<table schema="" tableName="finance_synchronization"
    			domainObjectName="financeSynchronization"
    			enableCountByExample="false" enableSelectByExample="false"
    			enableDeleteByExample="false" enableUpdateByExample="false"
    			selectByExampleQueryId="false">
    		</table>
    		<!-- 可使用多个表进行生成 -->
    		<table schema="" tableName="finance_adjustment"
    			domainObjectName="financeAdjustment"
    			enableCountByExample="false" enableSelectByExample="false"
    			enableDeleteByExample="false" enableUpdateByExample="false"
    			selectByExampleQueryId="false">
    		</table>
    
    	</context>
    </generatorConfiguration>
    

    Mysql

    新建配置文件 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="bingniterId" targetRuntime="MyBatis3">
    		<!-- 生成mysql带有分页的sql的插件 自己配置 -->
            <plugin type="generator.MysqlPaginationPlugin" />
            <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
            <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
    
    		<!-- 是否生成注释 去除自动生成的注释 -->
    		<commentGenerator>
    			<property name="suppressDate" value="true" />
    
    			<property name="suppressAllComments" value="true" />
    		</commentGenerator>
    		<!-- 数据库连接配置 -->
    		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
    			connectionURL="jdbc:sqlserver://10.1.10.99:1433;DatabaseName=bingniter"
    			userId="sa" password="!QAZ2wsx" />
    
    		<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制 -->
    		<javaTypeResolver>
    			<property name="forceBigDecimals" value="false" />
    		</javaTypeResolver>
    
    		<!--配置生成的实体包 targetPackage:实体类包路径,默认存放在src目录下; targetProject:目标工程名 -->
    		<javaModelGenerator
    			targetPackage="com.bingniter.entity"
    			targetProject="项目名字 或者 src/main/java" />
    
    		<!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
    		<sqlMapGenerator targetPackage="com.bingniter.mapper"
    			targetProject="learn" />
    		<!--生成Dao类存放位置 -->
    		<javaClientGenerator type="XMLMAPPER"
    			targetPackage="com.bingniter.dao"
    			targetProject="项目名字 或者 src/main/java">
    			<property name="enableSubPackages" value="true" />
    		</javaClientGenerator>
    		<!--生成对应表及类名 -->
    		<!-- 配置表 schema:不用填写 tableName: 表名 enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId: 
    			去除自动生成的例子 -->
    		<table schema="" tableName="finance_synchronization"
    			domainObjectName="financeSynchronization"
    			enableCountByExample="false" enableSelectByExample="false"
    			enableDeleteByExample="false" enableUpdateByExample="false"
    			selectByExampleQueryId="false">
    		</table>
    		<!-- 可使用多个表进行生成 -->
    		<table schema="" tableName="finance_adjustment"
    			domainObjectName="financeAdjustment" enableCountByExample="false"
    			enableSelectByExample="false" enableDeleteByExample="false"
    			enableUpdateByExample="false" selectByExampleQueryId="false">
    		</table>
    
    	</context>
    </generatorConfiguration>
    

    运行

    右键点击 generatorConfig.xml - Run Mybatis Generato
    ------------------------------------------------------------------------------------------
    MyBatis Generator Started...
    Buildfile: E:cps-workSpace.metadata.pluginsorg.mybatis.generator.eclipse.ui.generatedAntScriptslearn-generatorConfig.xml (1).xml
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    BUILD SUCCESSFUL
    MyBatis Generator Finished
  • 相关阅读:
    Android之旅 刷机 前言
    流程管理的售前意识
    站在企业角度来审视K2
    Android之旅 ROM定制 美化 默认屏的下方操作菜单
    在非K2服务器上部署基于K2的Web Application
    java拦截器与过滤器(转载)
    windows安装rediscluster集群
    SpringBoot使用Nacos配置中心(转载,可用)
    SpringBoot+Dubbo+MybatisPlus整合Seata分布式事务踩坑集合
    转载RabbitMQ教程
  • 原文地址:https://www.cnblogs.com/bingziweb/p/13829533.html
Copyright © 2011-2022 走看看