idea逆向工程没有生成文件解决方法

本文详细介绍了在IDEA中进行逆向工程的具体配置步骤,包括如何设置数据库驱动路径和MBG配置文件的绝对路径。同时展示了具体的配置代码示例,如数据库连接配置、生成POJO文件的位置设定等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:

idea使用逆向工程没有生成文件,将mbg的配置文件路径改为绝对路径,配置数据库驱动路径

如下

<!-- 
	MyBatis3Simple:基础班CRUD
	MyBatis3:复杂版CRUD
	 -->
	<classPathEntry location="C:\Users\122\.m2\repository\mysql\mysql-connector-java\5.1.37\mysql-connector-java-5.1.37.jar"/>
	<context id="DB2Tables" targetRuntime="MyBatis3Simple"><!--数据库简单操作修改成MyBatis3Simple-->
		<commentGenerator>
			<property name="suppressAllComments" value="true"/>
		</commentGenerator>
		<!-- jdbcConnection:指导连接到哪个数据库 -->
		<jdbcConnection 
			driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/ssm_crud"
			userId="root" 
			password="shiyinghan">
		</jdbcConnection>

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

		<!-- javaModelGenerator:生成pojo 
		targetPackage:生成的pojo放在哪个包
		targetProject:放在哪个工程下
		-->
		<javaModelGenerator targetPackage="SSM.bean"
			targetProject="D:\idea\Spring\SSM\src\main\java">
			<property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" />
		</javaModelGenerator>

		<!--sqlMapGenerator:sql映射文件生成器;指定xml生成的地方  -->
		<sqlMapGenerator targetPackage="mapper"
			targetProject="D:\idea\Spring\SSM\src\main\resources">
			<property name="enableSubPackages" value="true" />
		</sqlMapGenerator>

		<!-- javaClientGenerator:dao接口生成的地方 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="SSM.Dao"
			targetProject="D:\idea\Spring\SSM\src\main\java">
			<property name="enableSubPackages" value="true" />
		</javaClientGenerator>

		<!-- 
		table:指定要逆向生成哪个数据表
		tableName="t_cat":表名
		domainObjectName="":这个表对应的对象名
		 -->
		<table tableName="tbl_emp" domainObjectName="Employee"></table>
		<table tableName="tbl_dept" domainObjectName="Department"></table>

	</context>
</generatorConfiguration>

运行:

public class MBGtest {
        @Test
        public void test1() throws Exception {
                List<String> warnings = new ArrayList<String>();
                boolean overwrite = true;
                File configFile = new File("D:\\idea\\Spring\\SSM\\src\\main\\resources\\mbg.xml");
                ConfigurationParser cp = new ConfigurationParser(warnings);
                Configuration config = cp.parseConfiguration(configFile);
                DefaultShellCallback callback = new DefaultShellCallback(overwrite);
                MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
                        callback, warnings);
                //代码生成
                myBatisGenerator.generate(null);

        }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值