MyBatis数据库逆向生成工具

使用Mybatis数据库逆向生成工具

1.在pom中引入通用mapper工具

    <!-- 通用mapper逆向工具 -->
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>1.2.4</version>
        </dependency>

2.在yml中引入mapper的配置

############################################################
#
# mybatis mapper 配置
#
############################################################
# 通用 Mapper 配置
mapper:
  mappers: com.saddam.my.mapper.MyMapper
  not-empty: false    # 在进行数据库操作的的时候,判断表达式 username != null, 是否追加 username != ''
  identity: MYSQL

3.引入MyMapper接口类

/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2014-2016 abel533@gmail.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.saddam.my.mapper;

import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

/**
 * 继承自己的MyMapper
 */
public interface MyMapper<T> extends Mapper<T>, MySqlMapper<T> {
}

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis提供了一个叫做MyBatis Generator的插件,可以帮助我们快速地生成Java代码。以下是逆向生成JavaBean的步骤: 1.在pom.xml中添加MyBatis Generator的依赖: ``` <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.4.0</version> </dependency> ``` 2.在项目中创建配置文件generatorConfig.xml,并配置数据库连接信息、生成的JavaBean的包名、表名等信息。 3.在generatorConfig.xml中配置生成JavaBean的插件: ``` <plugin type="org.mybatis.generator.plugins.JavaModelGeneratorPlugin"> <property name="targetPackage" value="com.example.model"/> <property name="targetProject" value="src/main/java"/> </plugin> ``` 4.在generatorConfig.xml中配置生成Mapper接口的插件: ``` <plugin type="org.mybatis.generator.plugins.MapperInterfaceGeneratorPlugin"> <property name="targetPackage" value="com.example.mapper"/> <property name="targetProject" value="src/main/java"/> </plugin> ``` 5.在generatorConfig.xml中配置生成Mapper映射文件的插件: ``` <plugin type="org.mybatis.generator.plugins.SqlMapGeneratorPlugin"> <property name="targetPackage" value="mapper"/> <property name="targetProject" value="src/main/resources"/> </plugin> ``` 6.在generatorConfig.xml中配置要生成JavaBean的表名: ``` <table tableName="user"/> ``` 7.运行MyBatis Generator,生成JavaBean、Mapper接口以及Mapper映射文件: ``` java -jar mybatis-generator-core-1.4.0.jar -configfile generatorConfig.xml -overwrite ``` 以上就是使用MyBatis Generator逆向生成JavaBean的步骤。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值