Mybatis的代码生成工具

SSM中使用步骤

1、在 pom.xml 添加插件

pom.xml


<plugin>
    <groupId>org.mybatis.generatorgroupId>
    <artifactId>mybatis-generator-maven-pluginartifactId>
    <version>1.3.7version>
    <configuration>
        <configurationFile>${basedir}/src/main/resources/generatorConfig.xmlconfigurationFile>
        <overwrite>trueoverwrite>
        <verbose>trueverbose>
    configuration>
plugin>

2、在资源目录下添加配置文件

generatorConfig.xml


DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
    
    <classPathEntry  location="D:\mysql-connector-java-8.0.18.jar"/>

    
    <context id="DB2Tables" targetRuntime="MyBatis3">

        <commentGenerator>
            
            <property name="suppressAllComments" value="true"/>
        commentGenerator>

        
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/test?serverTimezone=UTC"
                        userId="root"
                        password="root">
        jdbcConnection>

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

        
        <javaModelGenerator targetPackage="cn.hyl.demo.model" targetProject=".\src\main\java">
        javaModelGenerator>

        
        <sqlMapGenerator targetPackage="cn.hyl.demo.dao" targetProject=".\src\main\java">
            <property name="enableSubPackages" value="true"/>
        sqlMapGenerator>

        
        
        <javaClientGenerator type="XMLMAPPER" targetPackage="cn.hyl.demo.dao" targetProject=".\src\main\java">
            <property name="enableSubPackages" value="true"/>

            
            
        javaClientGenerator>

        
        
        
        
        <table tableName="t_admin" domainObjectName="Admin"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false">
        table>

    context>
generatorConfiguration>

3、在 D 盘下放入 mysql-connector-java-8.0.18.jar

路径根据文件可以修改;版本无所谓

4、在 Maven 中使用配置好的插件

你可能感兴趣的:(ssm,mybatis,java)