关于自动生成mapper文件配置 总结 generatorConfig.xml 与pom

 

     mybatis-generator:generate 

<?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>
  <classPathEntry
	location="E:\maven\soft-maven\com\oracle\ojdbc6\11.1.0.7.0\ojdbc6-11.1.0.7.0.jar"/>
	
	  <!-- TDS 2018.5.18关于自动生成mapper文件配置 总结
	  1,数据库为oracle 2, 要数据库建了有了表才能生成mapper 
	  3,在pom文件最后配置<build>.4项目run as Maven build
(mybatis-generator:generate maven命令) 运行成功便生成了对应得mapper文件
	  下面附上build 配置-->
	  <!-- 
	<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/generatorConfig.xml</configurationFile>
                    <overwrite>true</overwrite>
                    <verbose>true</verbose>
                </configuration>
            </plugin>
     	
		</plugins>
	</build>-->
	
  <context id="context1">
    <commentGenerator>
        <property name="suppressAllComments" value="true" />
    </commentGenerator>
    <jdbcConnection connectionURL="jdbc:oracle:thin:@//172.20.19.205:1521/epay" 
        driverClass="oracle.jdbc.driver.OracleDriver" password="自己的数据库密码" userId="ecard" />
        
         <!-- 实体类生成的位置 -->
    <javaModelGenerator targetPackage="com.epcc.model" targetProject="E:\STS\epcc\src\main\java\com\epcc\dao\BsecontractOrderMapper1.java" >
     <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
    </javaModelGenerator>
    
    <!-- *Mapper.xml 文件的位置 -->
    <sqlMapGenerator targetPackage="com.epcc.dao" targetProject="E:\STS\epcc\src\main\resources\" >
    <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>
        
          <!-- Mapper 接口文件的位置 -->
    <javaClientGenerator targetPackage="com.efps.epcc.dao" targetProject="E:\STS\epcc\src\main\java\com\epcc\dao\BsecontractOrder\" type="XMLMAPPER" >
     <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>
       
     <!--自动生成mapper ,前面是表名,后面是生成的类名 -->
      <table tableName="EPCC_BSECONTRACT_ORDER" domainObjectName="BsecontractOrder2"
		enableCountByExample="false" enableUpdateByExample="false"
		enableDeleteByExample="false" enableSelectByExample="false"
		selectByExampleQueryId="false">
    </table> 

     <!--自动生成mapper ,前面是表名,后面是生成的类名 其他表-->
    <!-- <table tableName="EPCC_SIGNCONTRACT_INFO" domainObjectName="SignContractInfo"
		enableCountByExample="false" enableUpdateByExample="false"
		enableDeleteByExample="false" enableSelectByExample="false"
		selectByExampleQueryId="false">
    </table> 
    
    <table tableName="EPCC_AGREEMENTPAY_ORDER" domainObjectName="AgreementPayOrder"
		enableCountByExample="false" enableUpdateByExample="false"
		enableDeleteByExample="false" enableSelectByExample="false"
		selectByExampleQueryId="false">
    </table> 
  
  
    
  </context>
</generatorConfiguration>

===============================================================================================

二,关于方法配置参数问题

Dao里的方法字段与mapper.xml里的字段一样即可

 

 

 

 

 

 

 

1.在springboot中 一对于mapper文件结构一定要对应,xml的位置要在相同结构的包下.不然会报无效引用,如图

 

2.对于maven生成的mapper,如果你生成了2次或以上,很可能sql会生成两份在同一个mapper中,导致无法运行.下面这个是正常的.

 

 

 

 

最后总结:遇到程序报错,一定要冷静,有错,一定是自己那些地方没写正确,或者问题没找到.不要怀疑代码,更不要怀疑自己!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值