java使用generator快速生成服务类

1、在pom.xml中添加插件

<plugin>
                
                <groupId>org.mybatis.generatorgroupId>
                <artifactId>mybatis-generator-maven-pluginartifactId>
                <version>1.3.7version>
                <configuration>
                    
                    <configurationFile>src/main/resources/mybatis/generator-config.xmlconfigurationFile>
                    <verbose>trueverbose>
                    <overwrite>trueoverwrite>
                configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifactsid>
                        <goals>
                            <goal>generategoal>
                        goals>
                    execution>
                executions>
                <dependencies>
                    <dependency>
                        <groupId>mysqlgroupId>
                        <artifactId>mysql-connector-javaartifactId>
                        <version>5.1.40version>
                    dependency>
                    
                    <dependency>
                        <groupId>org.mybatis.generatorgroupId>
                        <artifactId>mybatis-generator-coreartifactId>
                        <version>1.3.7version>
                    dependency>
                dependencies>
            plugin>

2、在resource中添加generator-config.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>
    <context id="context" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
        commentGenerator>
        
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://ip:port/wishbuild" userId="1" password="1"/>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        javaTypeResolver>
        
        <javaModelGenerator targetPackage="com.project.bootstrap.entity" targetProject=".\src\main\java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        javaModelGenerator>
        
        <sqlMapGenerator targetPackage="com.project.bootstrap.mapper" targetProject=".\src\main\java">
            <property name="enableSubPackages" value="false"/>
        sqlMapGenerator>
        
        <javaClientGenerator targetPackage="com.project.bootstrap.mapper" targetProject=".\src\main\java" type="XMLMAPPER">
            <property name="enableSubPackages" value="false"/>
        javaClientGenerator>
        
        <table tableName="temp_track_node" domainObjectName="TempTrackNode" enableCountByExample="false"  enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
    context>
generatorConfiguration>

3、添加maven的启动配置

           java使用generator快速生成服务类_第1张图片

你可能感兴趣的:(java使用generator快速生成服务类)