IDEA中maven加入mybatis自动生成代码(ORACLE)

1.在pom文件中加入

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <configurationFile>src/main/resources/generator.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.2</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>

    </build>

2.在resource中加入generation.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 驱动jar包路径.用了相对路径 ,要在项目中外部引包-->
	<classPathEntry location="E:\projects\book\lib\ojdbc6_g-11.2.0.1.0.jar" />

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

		<!-- 为了防止生成的代码中有很多注释,比较难看,加入下面的配置控制 -->
		<commentGenerator>
			<property name="suppressAllComments" value="true" />
			<property name="suppressDate" value="true" />
		</commentGenerator>
		<!-- 注释控制完毕 -->

		<!-- 数据库连接, -->
		<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"
						connectionURL="jdbc:oracle:thin:@localhost:1521/orcl"
						userId="XXX"
						password="XXX">
		</jdbcConnection>

		<javaTypeResolver >
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>

		<!-- 数据表对应的model 层 ,targetProject为自动生成后文件所放路径 -->
		<javaModelGenerator targetPackage="com.cy.entity" targetProject="src/main/java">
			<property name="enableSubPackages" value="false" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>

		<!-- sql mapper 隐射配置文件,后面记得将这个文件移到resources底下,
		IDEA只在这个底下才能识别到mapper文件 -->
		<sqlMapGenerator targetPackage="com.cy.mapper"  targetProject="src/main/java">
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>

		<!-- 在ibatis2 中是dao层,但在mybatis3中,其实就是mapper接口 -->
		<javaClientGenerator type="XMLMAPPER" targetPackage="com.cy.dao"  targetProject="src/main/java">
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>

		<!-- 要对那些数据表进行生成操作,必须要有一个. -->
		<table tableName="reader" domainObjectName="Reader"
			   enableCountByExample="false" enableUpdateByExample="false"
			   enableDeleteByExample="false" enableSelectByExample="false"
			   selectByExampleQueryId="false">
		</table>
		<table tableName="book" domainObjectName="Book"
			   enableCountByExample="false" enableUpdateByExample="false"
			   enableDeleteByExample="false" enableSelectByExample="false"
			   selectByExampleQueryId="false">
		</table>
		<table tableName="admain" domainObjectName="Admain"
			   enableCountByExample="false" enableUpdateByExample="false"
			   enableDeleteByExample="false" enableSelectByExample="false"
			   selectByExampleQueryId="false">
		</table>
	</context>
</generatorConfiguration>

3.在IDEA run中添加配置


选择新建run

然后按步骤新建

接着在name中可以输入generator,在command line中输入mybatis-generator:generate -e;然后点击apply应用

转载(一个是Myeclipse一个是IDEA):https://blog.csdn.net/weixin_41624645/article/details/80911851
https://blog.csdn.net/tanga842428/article/details/72356520

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值