idea 使用 mybatis-generator

来源:互联网 发布:唐努乌梁海 知乎 编辑:程序博客网 时间:2024/05/16 03:31

系统环境:

jdk:1.7

idea:14

maven:3.1.1

第一步:创建maven项目(maven配置此处不说)


直接next


填写groupId和artifactId,然后next


finish。

第二步:编辑pom.xml

<?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.cc520</groupId>    <artifactId>mybatis-generator</artifactId>    <version>1.0-SNAPSHOT</version>    <build>        <finalName>520cc</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></project>

第三步:在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>    <!--数据库的jdbc驱动jar包的位置 -->    <classPathEntry location="D:/mysql-connector-java-5.1.30-bin.jar"/>    <context id="default" targetRuntime="MyBatis3">        <!-- optional,旨在创建class时,对注释进行控制 -->        <commentGenerator>            <property name="suppressDate" value="true" />        </commentGenerator>        <!--jdbc的数据库连接 -->        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/ssm" userId="root" password="root">        </jdbcConnection>        <javaModelGenerator targetPackage="com.c520l.domain" targetProject="src/main/java">            <!--构造函数 -->            <property name="constructorBased" value="true"/>            <!-- 是否允许子包,即targetPackage.schemaName.tableName -->            <property name="enableSubPackages" value="false"/>            <!-- 建立的对象是否有setter方法 false为有 true为没有 -->            <property name="immutable" value="false"/>            <!-- 对象的父类 -->            <!--<property name="rootClass" value="com.c520l."/>-->            <!-- 是否对类CHAR类型的列的数据进行trim操作 -->            <property name="trimStrings" value="true"/>        </javaModelGenerator>        <!--Mapper映射文件生成所在的目录 -->        <sqlMapGenerator targetPackage="com.c520l.mapping" targetProject="src/main/java">            <property name="enableSubPackages" value="false"/>        </sqlMapGenerator>        <javaClientGenerator targetPackage="com.c520l.dao" targetProject="src/main/java" type="MIXEDMAPPER">            <property name="enableSubPackages" value=""/>            <property name="exampleMethodVisibility" value=""/>            <property name="methodNameCalculator" value=""/>            <property name="rootInterface" value=""/>        </javaClientGenerator>        <table schema="general" tableName="user" domainObjectName="user"               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"               enableSelectByExample="false" selectByExampleQueryId="false" >            <property name="useActualColumnNames" value="true"/>        </table>    </context></generatorConfiguration>  
第四部:配置运行



在command line中填写:

mybatis-generator:generate -e


ok,小功告成。

参考网络多篇博文整合而成。




0 0
原创粉丝点击