码迷,mamicode.com
首页 > 移动开发 > 详细

sts使用mybatis插件直接生成数据库表的mapper类及配置文件

时间:2019-06-26 15:03:11      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:自动   ati   class   public   配置   bat   package   后缀   example   

首先点击help------》Eclipse Marketplace----->在find中搜索mybatis下面图片的第一个 点击installed

技术图片

还需要一个配置文件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>
    <context id="context1">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
        <jdbcConnection
            connectionURL="jdbc:mysql://localhost:3306/books?serverTimezone=GMT%2B8"
            driverClass="com.mysql.cj.jdbc.Driver" password="root" userId="root" />
        <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 
            和 NUMERIC 类型解析为java.math.BigDecimal -->
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>


        <!-- targetProject:生成PO类的位置 -->
        <javaModelGenerator targetPackage="cn.books.model"
            targetProject="books/src">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
            <!-- 从数据库返回的值被清理前后的空格 -->
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <!-- targetProject:mapper映射文件生成的位置 -->
        <sqlMapGenerator targetPackage="cn.books.dao"
            targetProject="books/src">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
        </sqlMapGenerator>

        <!-- targetPackage:mapper接口生成的位置 -->
        <javaClientGenerator type="XMLMAPPER"
            targetPackage="cn.books.dao" targetProject="books/src">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
        </javaClientGenerator>
        
        <!--生成对应表及类名 如果以往生成过的则在再次运行这个xml文件是要删除以往建mapper的代码-->
        <table tableName="userinfo" domainObjectName="Userinfo"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false">
            <property name="useActualColumnNames" value="true"/>
        </table>
        
    </context>
</generatorConfiguration>

然后运行这个配置文件

运行选项使用这个插件运行(mybatis Generator)

sts使用mybatis插件直接生成数据库表的mapper类及配置文件

标签:自动   ati   class   public   配置   bat   package   后缀   example   

原文地址:https://www.cnblogs.com/Web-spring/p/11089852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!