zoukankan      html  css  js  c++  java
  • mybatis自动生成@Table、@Column、@Id注解

    在pom.xml中添加如下插件以及插件相关的依赖

    <build>
    		<plugins>
    			<plugin>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-maven-plugin</artifactId>
    				<executions>
    					<execution>
    						<goals>
    							<goal>repackage</goal>
    						</goals>
    					</execution>
    				</executions>
    			</plugin>
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-compiler-plugin</artifactId>
    				<version>2.3.2</version>
    				<configuration>
    					<source>1.8</source>
    					<target>1.8</target>
    				</configuration>
    			</plugin>
    			<!-- mybatis generator 自动生成代码插件 -->
    			<plugin>
    				<groupId>org.mybatis.generator</groupId>
    				<artifactId>mybatis-generator-maven-plugin</artifactId>
    				<version>1.3.6</version>
    				<configuration>
    					<!--配置文件的位置-->
    					<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
    					<overwrite>true</overwrite>
    					<verbose>true</verbose>
    				</configuration>
                    <dependencies>
    					<dependency>
    						<groupId>com.thunisoft.arterybase</groupId>
    						<artifactId>ArteryBase</artifactId>
    						<version>3.6.2.2</version>
    					</dependency>
                        <dependency>
                            <groupId>tk.mybatis</groupId>
                            <artifactId>mapper</artifactId>
                            <version>4.0.0</version>
                        </dependency>
                    </dependencies>
    			</plugin>
    		</plugins>
    	</build>
    

    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 这里选择自己本地位置-->
        <classPathEntry location="D:Maven
    epositorycom	hunisoftarterybaseArteryBase3.6.2.2ArteryBase-3.6.2.2.jar" />
        <context id="testTables" targetRuntime="MyBatis3Simple" defaultModelType="flat">
    
            <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
                <property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
                <property name="forceAnnotation" value="true"/>
                <property name="caseSensitive" value="true"/>
            </plugin>
    
            <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
            <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                            connectionURL="jdbc:mysql://localhost:3306/dbdicom"
                            userId="root"
                            password="root">
            </jdbcConnection>
            <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true
             时把JDBC DECIMAL 和
               NUMERIC 类型解析为java.math.BigDecimal -->
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
    
            <!-- 生成模型(PO)的包名和位置 -->
            <javaModelGenerator targetPackage="com.angus.entity"
                                targetProject="src/main/java">
                <!-- enableSubPackages:是否让schema作为包的后缀 -->
                <property name="enableSubPackages" value="false" />
                <!-- 从数据库返回的值被清理前后的空格 -->
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
    
            <!--&lt;!&ndash; 生成映射文件的包名和位置&ndash;&gt;-->
            <!--<sqlMapGenerator targetPackage="main.resources.mapping"-->
                             <!--targetProject="src">-->
                <!--&lt;!&ndash; enableSubPackages:是否让schema作为包的后缀 &ndash;&gt;-->
                <!--<property name="enableSubPackages" value="false" />-->
            <!--</sqlMapGenerator>-->
    
            <!--&lt;!&ndash; 生成DAO的包名和位置&ndash;&gt;-->
            <!--<javaClientGenerator type="XMLMAPPER"-->
                                 <!--targetPackage="com.angus.dao"-->
                                 <!--targetProject="src/main/java">-->
                <!--&lt;!&ndash; enableSubPackages:是否让schema作为包的后缀 &ndash;&gt;-->
                <!--<property name="enableSubPackages" value="false" />-->
            <!--</javaClientGenerator>-->
    
            <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是
          实体类名-->
            <table tableName="t_message" domainObjectName="Message"
                   enableCountByExample="false" enableUpdateByExample="false"
                   enableDeleteByExample="false" enableSelectByExample="false"
                   selectByExampleQueryId="false"></table>
        </context>
    </generatorConfiguration>
    

    启动

    启动maven

    参考网站

    代码地址

    作者可能会修改文档地址:文档地址

  • 相关阅读:
    树莓派系统Raspbian安装小结
    树莓派安装centos 7系统
    Ubuntu下安装SSH服务
    使用xUnit为.net core程序进行单元测试(4)
    使用xUnit为.net core程序进行单元测试(3)
    使用xUnit为.net core程序进行单元测试 -- Assert
    使用xUnit为.net core程序进行单元测试(1)
    用 Identity Server 4 (JWKS 端点和 RS256 算法) 来保护 Python web api
    asp.net core 2.0 查缺补漏
    "软件随想录" 读书笔记
  • 原文地址:https://www.cnblogs.com/daleyzou/p/autoGenerateAnnotations.html
Copyright © 2011-2022 走看看