MyBatis Generator 配置文件自动生成

官网:http://mybatis.github.io/generator/index.html

项目目录结构

项目目录结构

添加Maven插件(pom.xml)

   <project ...>
     ...
     <build>
       ...
       <plugins>
        ...
        <plugin>
      	  <groupId>org.mybatis.generator</groupId>
      	  <artifactId>mybatis-generator-maven-plugin</artifactId>
          <version>1.3.2</version>
        </plugin>
        ...
      </plugins>
      ...
    </build>
    ...
  </project>

配置Maven执行命令

mybatis-generator:generate

** 右键 --> Run As --> Run Configurations... **

配置命令

配置命令

配置MyBatis GeneratorXML

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>
	<!-- 引入配置文件 -->
	<properties resource="init.properties" />
	<!-- JDBC驱动 -->
	<classPathEntry location="${class_path}" />

	<context id="Tables" targetRuntime="MyBatis3">

		<!-- 注释 -->
		<commentGenerator>
			<property name="suppressAllComments" value="true" /><!-- 是否取消注释 -->
			<property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳 -->
		</commentGenerator>

		<!-- JDBC连接 -->
		<jdbcConnection driverClass="${jdbc_driver}"
			connectionURL="${jdbc_url}/${schema}" userId="${jdbc_user}" password="${jdbc_password}">
		</jdbcConnection>

		<!-- 类型转换 -->
		<javaTypeResolver>
			<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<!-- 生成实体类地址 -->
		<javaModelGenerator targetPackage="model"
			targetProject="${target_project}">
			<property name="enableSubPackages" value="false" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>

		<!-- 生成mapxml文件 -->
		<sqlMapGenerator targetPackage="xml" targetProject="${target_project}">
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>

		<!-- 生成mapxml对应client-->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="dao" targetProject="${target_project}">
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>

		<!-- 配置表信息 -->
		<!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample 
			是否生成 example类 -->
		<table schema="${schema}" tableName="${table_name}"
			domainObjectName="${domain_object_name}" enableCountByExample="false"
			enableDeleteByExample="false" enableSelectByExample="false"
			enableUpdateByExample="false" />

	</context>
</generatorConfiguration>

init.properties

#Mybatis Generator configuration  
#JDBC驱动
class_path=C:\\Users\\Administrator\\.m2\\repository\\mysql\\mysql-connector-java\\5.1.9\\mysql-connector-java-5.1.9.jar 
#驱动
jdbc_driver=com.mysql.jdbc.Driver
#数据库连接
jdbc_url=jdbc:mysql://localhost:3306
#数据库用户名
jdbc_user=ROOT
#数据库密码
jdbc_password=******
#项目位置
target_project=src\\main\\java
#数据库
schema=vcdb
#数据库表
table_name=table
#model类名
domain_object_name=Model

执行运行命令

** 右键 --> Run As --> Maven build **

运行

日志

F5刷新项目

转载于:https://my.oschina.net/mleo/blog/522910

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值