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\repository\com\thunisoft\arterybase\ArteryBase\3.6.2.2\ArteryBase-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

參考網站

代碼地址

作者可能會修改文檔地址:文檔地址

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章