import java.io.File;
import java.util.ArrayList;
import java.util.List; import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback; public class GeneratorSqlmap { public void generator() throws Exception{ List<String> warnings = new ArrayList<String>(); boolean overwrite = true; //指定 逆向工程配置文件
File configFile = new File("generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configFile);
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null); } public static void main(String[] args) throws Exception { try {
GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
generatorSqlmap.generator();
} catch (Exception e) {
e.printStackTrace();
} } }

  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="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator> <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/hotel" userId="root"
password="root">
</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.hotel.pojo" targetProject=".\src"> <!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" /> <!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>       <!-- targetProject:mapper映射文件生成的位置 -->
<sqlMapGenerator targetPackage="com.hotel.mapper" targetProject=".\src"> <!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator> <!-- targetPackage:mapper接口生成的位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.hotel.mapper" targetProject=".\src">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator> <!-- 指定数据库表 -->
<table schema="" tableName="tb_account"></table>
<table schema="" tableName="tb_guest"></table>
<table schema="" tableName="tb_consumption"></table>
<table schema="" tableName="tb_history"></table>
<table schema="" tableName="tb_privilege"></table>
<table schema="" tableName="tb_room"></table>
<table schema="" tableName="tb_roomtype"></table>
<table schema="" tableName="tb_user"></table> </context>
</generatorConfiguration>

  相关文件截图:

mybatis逆向工程生成JavaBean、dao、mapper generatorSqlmapCustom的更多相关文章

  1. Mybatis逆向工程生成po、mapper接口、mapper.xml

    Mybatis逆向工程生成po.mapper接口.mapper.xml 一.新建一个maven工程 请查看我的另一篇博客:<使用idea创建一个maven工程> 二.引入所需依赖 需要my ...

  2. MyBatis逆向工程生成配置 generator (生成pojo、mapper.xml、mapper.java)

    MyBatis逆向工程生成 mybatis需要程序员自己编写sql语句,mybatis官方提供逆向工程,可以针对单表自动生成mybatis执行所需要的代码(mapper.java.mapper.xml ...

  3. MyBatis逆向工程生成的Example类的方法总结

    很早之前就在项目开发中多次使用MyBatis逆向工程生成的Example类,但一直没有对其下的方法做一个简单的总结,现总结如下:一.mapper接口中的方法解析mapper接口中的部分常用方法及功能如 ...

  4. 使用最新版Mybatis逆向工程生成属性不全的问题

    这是出现问题时打印的日志 首先查看表内的字段 这张User表含8个属性,但是在逆向工程过程中生成的Pojo类不全还出现了不存在的属性 主要在逆向工程过程中的一个配置问题,修改generatorConf ...

  5. MyBatis 使用Generator自动生成Model , Dao, mapper

    最近   我新建了一 个maven 项目,使用的是spring + springmvc + mybatis框架. 听说Mybatis可以自动生成model和mapper以及dao层,我就从网上查了查资 ...

  6. Mybatis逆向工程生成类文件

    首先,我们需要建好相关文件夹目录: 然后,编写执行脚本 generator.xml : 1 <?xml version="1.0" encoding="UTF-8& ...

  7. mybatis逆向工程生成mapper报错

    Result Maps collection already contains value for xxxMapper.BaseResultMap错误解决办法一.问题描述今天在做项目时,遇到一个错误: ...

  8. MyBatis逆向工程生成dao层增删改查方法解释使用(转载)

    int countByExample(BUserExample example); //根据条件查询数量 /** * 示例 * public int countByExample() { * BUse ...

  9. mybatis逆向工程生成代码

    1 什么是逆向工程 mybaits需要程序员自己编写sql语句,mybatis官方提供逆向工程 可以针对单表自动生成mybatis执行所需要的代码(mapper.java,mapper.xml.po. ...

随机推荐

  1. 未能加载文件或程序集“System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”或它的某一个依赖项。系统找不到指定的文件

    ASP.NET 运行时错误:针对类型System.Web.Mvc.PreApplicationStartCode的应用程序邓启动初始化方法Start 引发了异常,显示下列错误消息: 未能加载文件或程序 ...

  2. [LeetCode] Longest Repeating Character Replacement 最长重复字符置换

    Given a string that consists of only uppercase English letters, you can replace any letter in the st ...

  3. [LeetCode] Basic Calculator 基本计算器

    Implement a basic calculator to evaluate a simple expression string. The expression string may conta ...

  4. 如何在ASP.NET Core中使用Redis

    注:本文提到的代码示例下载地址> https://code.msdn.microsoft.com/How-to-use-Redis-in-ASPNET-0d826418 Redis是一个开源的内 ...

  5. 用EmEditor实现PDF转Word后的对齐排版

    Redraw = false//禁止重绘(类似于VBA中的: Application.screenupdating=FALSE),以提高运行效率 //去除所有空行和只由空白字符构成的行 documen ...

  6. Jmeter学习笔记ONE

    最近想学一些关于性能测试方面的知识,其实之前已经初步了解了Jmeter工具,它是一个轻量级的性能测试工具,开源并且免费,相比于Loadrunner来说用起来更简便. JMeter 可以用于对服务器.网 ...

  7. Android Studio导入项目遇到的问题

    [ Failed to resolve: com.afollestad:material-dialogs:0.7.5.5] 解决办法: 1.打开app目录下的build.gradle文件,然后在and ...

  8. C++中重定义的问题——问题的实质是声明和定义的关系以及分离式编译的原理

    这里的问题实质是我们在头文件中直接定义全局变量或者函数,却分别在主函数和对应的cpp文件中包含了两次,于是在编译的时候这个变量或者函数被定义了两次,问题就出现了,因此,我们应该形成一种编码风格,即: ...

  9. fedora22,fedora24最简单的安装virtaulbox的方法

    fedora为什么不好用呢? 1.因为很多软件没有预先安装,新手安装时,就无从下手了. 2.版本更新太快,有老手提供了解决方案,但是版本更新了,新手按照步骤来,就不能配置成功! 不抱怨了. 安装vir ...

  10. 内存VSS/RSS/PSS/USS名词解释

    VSS(virtual set size)虚拟耗用内存(包含共享库占用的内存) RSS(Resident set size)实际使用物理内存(包含共享库占用的内存) RSS是进程实际驻存在物理内存的部 ...