zoukankan      html  css  js  c++  java
  • spring boot 自动生成数据库对应的实体类和mapping文件

    1、数据库创建好表。

    2、srcmain esourcesmybatismybatis-generator.xml  创建mybatis-generator.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>

    <!-- 本地数据库驱动程序jar包的全路径 -->
    <classPathEntry location="D: epomysqlmysql-connector-java8.0.21"/>

    <context id="context" targetRuntime="MyBatis3">
    <commentGenerator>
    <property name="suppressDate" value="true"/>
    <property name="suppressAllComments" value="true" />
    <!--其中suppressDate是去掉生成日期那行注释,suppressAllComments是去掉所有的注-->
    </commentGenerator>

    <!-- 数据库的相关配置 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="-----" userId="--" password="--"/>

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

    <!-- 实体类生成的位置 -->
    <javaModelGenerator targetPackage="com.example.mybatisdemo.entity" targetProject="src/main/java">
    <property name="enableSubPackages" value="false"/>
    <property name="trimStrings" value="true"/>
    </javaModelGenerator>

    <!-- *Mapper.xml 文件的位置 -->
    <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources/mybatis">
    <property name="enableSubPackages" value="false"/>
    </sqlMapGenerator>

    <!-- Mapper 接口文件的位置 -->
    <javaClientGenerator targetPackage="com.example.mybatisdemo.daomapper" targetProject="src/main/java" type="XMLMAPPER">
    <property name="enableSubPackages" value="false"/>
    </javaClientGenerator>

    <table tableName="mysql_student" domainObjectName="Student" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
    </context>
    </generatorConfiguration>
    3、配置pom文件:
    build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    </plugin>
    <plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.5</version>
    <dependencies>
    <dependency>
    <groupId> mysql</groupId>
    <artifactId> mysql-connector-java</artifactId>
    <version> 8.0.21</version>
    </dependency>
    <dependency>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-core</artifactId>
    <version>1.3.5</version>
    </dependency>
    </dependencies>
    <executions>
    <execution>
    <id>Generate MyBatis Artifacts</id>
    <phase>package</phase>
    <goals>
    <goal>generate</goal>
    </goals>
    </execution>
    </executions>
    <configuration>
    <!--允许移动生成的文件 -->
    <verbose>true</verbose>
    <!-- 是否覆盖 -->
    <overwrite>true</overwrite>
    <!-- 自动生成的配置 -->
    <configurationFile>
    src/main/resources/mybatis/mybatis-generator.xml</configurationFile>
    </configuration>
    </plugin>
    </plugins>
    </build>
    4、执行

  • 相关阅读:
    $(document).Ready()方法 VS OnLoad事件 VS $(window).load()方法
    ASP.NET MVC之文件上传【二】
    ASP.NET MVC之文件上传【一】
    [JSOI2009]球队收益
    Codeforces 323 B Tournament-graph
    2017 [六省联考] T6 寿司餐厅
    [CQOI2014]数三角形
    Hdoj 3506 Monkey Party
    Loj #125. 除数函数求和(2)
    Codeforces 235 E Number Challenge
  • 原文地址:https://www.cnblogs.com/danyuzhu11/p/15525894.html
Copyright © 2011-2022 走看看