首页 > 学院 > 开发设计 > 正文

mybatis-generator IDEA 使用方法

2019-11-06 07:57:53
字体:
来源:转载
供稿:网友

1,用IDEA新建maven工程

2,pom 文件中写入需要的jar包

<?xml version="1.0" encoding="UTF-8"?><PRoject xmlns="http://maven.apache.org/POM/4.0.0"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelVersion>4.0.0</modelVersion>    <groupId>com.MavenMybaits</groupId>    <artifactId>MavenMybaits</artifactId>    <version>1.0-SNAPSHOT</version>    <build>        <plugins>            <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>                    <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>                    <!-- MySQL -->                    <dependency>                        <groupId>mysql</groupId>                        <artifactId>mysql-connector-java</artifactId>                        <version>5.1.32</version>                    </dependency>                </dependencies>            </plugin>        </plugins>    </build></project>
3,在src/main/resources 新建 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>    <!--mysql 连接数据库jar 这里选择自己本地位置-->     <context id="testTables" targetRuntime="MyBatis3">              <commentGenerator>            <!-- 是否去除自动生成的注释 true:是 : false:否 -->            <property name="suppressAllComments" value="true" />        </commentGenerator>        <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->        <jdbcConnection driverClass="com.mysql.jdbc.Driver"                        connectionURL="jdbc:mysql://localhost:3306/taotao" userId="root"                        passWord="root">        </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.taotao.pojo"                            targetProject="src/main/java">            <!-- enableSubPackages:是否让schema作为包的后缀 -->            <property name="enableSubPackages" value="false" />            <!-- 从数据库返回的值被清理前后的空格 -->            <property name="trimStrings" value="true" />        </javaModelGenerator>        <!-- targetProject:mapper映射文件生成的位置           如果maven工程只是单独的一个工程,targetProject="src/main/java"           若果maven工程是分模块的工程,targetProject="所属模块的名称",例如:           targetProject="ecps-manager-mapper",下同-->        <sqlMapGenerator targetPackage="com.taotao.mapper"                         targetProject="src/main/java">            <!-- enableSubPackages:是否让schema作为包的后缀 -->            <property name="enableSubPackages" value="false" />        </sqlMapGenerator>        <!-- targetPackage:mapper接口生成的位置 -->        <javaClientGenerator type="XMLMAPPER"                             targetPackage="com.taotao.mapper"                             targetProject="src/main/java">            <!-- enableSubPackages:是否让schema作为包的后缀 -->            <property name="enableSubPackages" value="false" />        </javaClientGenerator>        <!-- 指定数据库表 -->        <table schema="" tableName="tb_content"></table>        <table schema="" tableName="tb_content_category"></table>        <table schema="" tableName="tb_item"></table>        <table schema="" tableName="tb_item_cat"></table>        <table schema="" tableName="tb_item_desc"></table>        <table schema="" tableName="tb_item_param"></table>        <table schema="" tableName="tb_item_param_item"></table>        <table schema="" tableName="tb_order"></table>        <table schema="" tableName="tb_order_item"></table>        <table schema="" tableName="tb_order_shipping"></table>        <table schema="" tableName="tb_user"></table>    </context></generatorConfiguration>
4,配置编译环境
6,选择 你自己的编译环境运行出现你需要的文件
代码下载地址:https://github.com/cdwkios/MavenMybaits.git


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表