mybatis-generator for oracle

1.先去https://github.com/mybatis/generator/releases下载架包
2.设置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>
	
		<!-- 指定数据库连接驱动jar地址 -->
		<classPathEntry
			location="G:/mystudy/mybatis-generator-core-1.3.7/lib/ojdbc14-10.2.0.5.jar" />
			
		<!-- 一个数据库一个context --> 
		<context id="sqlserverTables">
			<!-- 生成的pojo,将implements Serializable -->
			<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
			
			<!-- 注释 -->
			<commentGenerator>
				<property name="suppressAllComments" value="true" /><!-- 是否取消注释 -->
				<!-- <property name="suppressDate" value="true" />  是否生成注释代时间戳 -->
			</commentGenerator>  
			
			<!-- 数据库链接URL、用户名、密码 -->
			<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
				connectionURL="jdbc:oracle:thin:@localhost:1521:ORCL" userId="system" 
				password="zhan123456">
			</jdbcConnection>
			
			<!-- 类型转换 -->
			<javaTypeResolver>
			<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 
				和 NUMERIC 类型解析为java.math.BigDecimal -->
				<property name="forceBigDecimals" value="false" />
			</javaTypeResolver>

			<!-- 生成model模型,对应的包路径,以及文件存放路径(targetProject),targetProject可以指定具体的路径,如./src/main/java, 
				也可以使用“MAVEN”来自动生成,这样生成的代码会在target/generatord-source目录下 -->
			<javaModelGenerator targetPackage="com.zhan.websys.entity"
				targetProject="./src/main/java">
				<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> 
				<property name="enableSubPackages" value="true" />
				<!-- 从数据库返回的值被清理前后的空格 -->
				<property name="trimStrings" value="true" />
			</javaModelGenerator>

			<!--对应的mapper.xml文件 -->
			<sqlMapGenerator targetPackage="com.zhan.websys.dao"
				targetProject="./src/main/java">
				<property name="enableSubPackages" value="true" />
			</sqlMapGenerator>

			<!-- 对应的Mapper接口类文件 -->
			<javaClientGenerator type="XMLMAPPER"
				targetPackage="com.zhan.websys.dao" targetProject="./src/main/java">
				<property name="enableSubPackages" value="false" />
			</javaClientGenerator>


			<!-- 列出要生成代码的所有表,这里配置的是不生成Example文件 -->
			<!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample   
		               是否生成 example类   -->  
			<table tableName="customer" domainObjectName="Customer"
				schema=""
				enableCountByExample="false" enableUpdateByExample="false"
				enableDeleteByExample="false" enableSelectByExample="false"
				selectByExampleQueryId="false">
				<!-- 忽略列,不生成bean 字段 
           		<ignoreColumn column="FRED" />-->   
				<!-- 指定列的java数据类型  
	            <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />  -->
				<!-- 用于指定生成实体类时是否使用实际的列名作为实体类的属性名。false是 Camel Case风格-->
				<property name="useActualColumnNames" value="false" />
			</table>
		</context>
	</generatorConfiguration>    
3.在当前目录下执行命令
Java -jar mybatis-generator-core-1.3.7.jar -configfile generatorConfig.xml -overwrite
注意,必须先创建src/main/java目录,不然无法生成文件

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值