Code Monkey home page Code Monkey logo

springboot_mybatis_generator's Introduction

MyBatis 逆向生成bean, mapper.xml

1. pom中添加mybatis逆向工程插件

		<!-- MyBatis 逆向工程 插件 -->
		<plugin>
			<groupId>org.mybatis.generator</groupId>
			<artifactId>mybatis-generator-maven-plugin</artifactId>
			<version>1.3.5</version>
			<configuration>
				<!--允许移动生成的文件-->
				<verbose>true</verbose>
				<!--允许覆盖生成的文件-->
				<overwrite>true</overwrite>
				<!--配置文件的路径 默认resources目录下-->
				<configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
			</configuration>
		</plugin>

2. src/main/resources目录下添加mybatis-generator.xml文件

<generatorConfiguration>
<!--mysql 连接数据库jar 这里选择自己本地位置-->
<classPathEntry
        location="D:\maven\repository\mysql\mysql-connector-java\5.1.9\mysql-connector-java-5.1.9.jar"/>
<context id="testTables" targetRuntime="MyBatis3">
    <commentGenerator>
        <!-- 是否去除自动生成的注释 true:是 : false:否 -->
        <property name="suppressAllComments" value="true"/>
    </commentGenerator>
    <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                    connectionURL="jdbc:mysql://localhost:3306/testscore?serverTimezone=UTC" userId="root"
                    password="123456">
    </jdbcConnection>
    <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
       NUMERIC 类型解析为java.math.BigDecimal -->
    <javaTypeResolver>
        <property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>

    <!-- targetProject:生成PO类的位置 -->
    <javaModelGenerator targetPackage="com.orangesay.entity"
                        targetProject="src/main/java">
        <!-- enableSubPackages:是否让schema作为包的后缀 -->
        <property name="enableSubPackages" value="false"/>
        <!-- 从数据库返回的值被清理前后的空格 -->
        <property name="trimStrings" value="true"/>
    </javaModelGenerator>
    <!-- targetProject:mapper映射文件生成的位置
       如果maven工程只是单独的一个工程,targetProject="src/main/java"
       若果maven工程是分模块的工程,targetProject="所属模块的名称",例如:
       targetProject="ecps-manager-mapper",下同-->
    <sqlMapGenerator targetPackage="mapper"
                     targetProject="src/main/resources">
        <!-- enableSubPackages:是否让schema作为包的后缀 -->
        <property name="enableSubPackages" value="false"/>
    </sqlMapGenerator>
    <!-- targetPackage:mapper接口生成的位置 -->
    <javaClientGenerator type="XMLMAPPER"
                         targetPackage="com.orangesay.mapper"
                         targetProject="src/main/java">
        <!-- enableSubPackages:是否让schema作为包的后缀 -->
        <property name="enableSubPackages" value="false"/>
    </javaClientGenerator>
    <!-- 指定数据库表  多个表示,可用多个table标签-->
    <table tableName="score"
           enableCountByExample="false"
           enableUpdateByExample="false"
           enableDeleteByExample="false"
           enableSelectByExample="false"
           selectByExampleQueryId="false">
    </table>
    <table tableName="t_user"
           enableCountByExample="false"
           enableUpdateByExample="false"
           enableDeleteByExample="false"
           enableSelectByExample="false"
           selectByExampleQueryId="false">
    </table>
</context>

3.右键点击项目名--》Run As-->Maven build-->在Goals中添加mybatis-generator:generate,点击apply然后run。运行完后刷新项目,就有自动生成的代码了。

springboot_mybatis_generator's People

Contributors

lyxshike avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.