idea 逆向工程 生成pojo, mapperInterface mapper.xml

 
 

1.创建maven工程
2.导入pom依赖
<dependencies>


            <dependency>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-core</artifactId>
                <version>1.3.3</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>3.2.8</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
        </dependencies>


    <build>
        <finalName>zsxt</finalName>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>
    </build>
3.编写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>
	<!-- classPathEntry:数据库的 JDBC驱动的jar 包地址 -->
	<classPathEntry
			location="D:/study/jar/mysql/mysql-connector-java-5.1.18-bin.jar" />
	<context id="caigouTables" targetRuntime="MyBatis3">
		<commentGenerator>
			<!-- 是否去除自动生成的注释 true:是 : false:否 -->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->

		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
						connectionURL="jdbc:mysql://127.0.0.1:3306/pinyougoudb" userId="root"
						password="root">
		</jdbcConnection>
		<!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
        connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg"
        userId="yycg"
        password="yycg">
        </jdbcConnection> -->
		<!-- 默认 false,把 JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把 JDBC DECIMAL 和
        NUMERIC 类型解析为java.math.BigDecimal -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		<!-- targetProject:生成 PO 类的位置 -->
		<javaModelGenerator targetPackage="com.pinyougou.pojo"	targetProject="src/main/java">
			<!-- enableSubPackages:是否让schema 作为包的后缀 -->
			<property name="enableSubPackages" value="true" />
			<!-- 从数据库返回的值被清理前后的空格 -->
			<property name="trimStrings" value="true" />
		</javaModelGenerator>





		<!-- targetProject:自动 mapper 接口的位置 -->
		<sqlMapGenerator targetPackage="com.pinyougou.mapper"  	 targetProject="./src/main/java">
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>
		<!-- 生成 XML文件 -->
		<javaClientGenerator type="XMLMAPPER"
							 targetPackage="com.pinyougou.mapper"  targetProject="./src/main/resources">
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>


		<table tableName="tb_user"></table>
		<table tableName="tb_content"></table>
		<table tableName="tb_content_category"></table>
		<table tableName="tb_item"></table>
		<table tableName="tb_item_cat"></table>
		<table tableName="tb_order"></table>
		<table tableName="tb_order_item"></table>
		<table tableName="tb_address"></table>
		<table tableName="tb_areas"></table>
		<table tableName="tb_brand"></table>
		<table tableName="tb_provinces"></table>
		<table tableName="tb_cities"></table>
		<table tableName="tb_seller"></table>
		<table tableName="tb_freight_template"></table>
		<table tableName="tb_specification"></table>
		<table tableName="tb_specification_option"></table>
		<table tableName="tb_type_template"></table>
		<table tableName="tb_goods"></table>
		<table tableName="tb_goods_desc"></table>
		<table tableName="tb_pay_log"></table>
		<table tableName="tb_seckill_goods"></table>
		<table tableName="tb_seckill_order"></table>
	</context>
</generatorConfiguration>

4.运行
  • mybatis-generator 插件

5.将生成的pojo,mapper, interface copy到自己的工程中



猜你喜欢

转载自blog.csdn.net/hlz5857475/article/details/80994078