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. 使用JavaMail发送邮件

    一.邮件的相关概念 邮件协议.主要包括: SMTP协议:Simple Mail Transfer Protocol,即简单邮件传输协议,用于发送电子邮件 POP3协议:Post Office Prot ...

  2. codevs 1164 统计数字

    时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题目描述 Description [问题描述]某次科研调查时得到了n个自然数,每个数均不超过150000000 ...

  3. Codeforces Round #383(div 2)

    A.快速幂 B. 题意:求ai^aj=x的数对个数,x和a[]给定 分析:a^b=c,则a^c=b,所以求ai^x=aj的个数,枚举一遍即可 C. 题意:给你一个有向图,每个点的出边只有一条,求最小的 ...

  4. websocket初探

    本文尚未完成,在此只写一些句子,以后慢慢整理. 一.参数 IllegalArgumentException No payload parameter present on the method[mes ...

  5. 【笔记】jstree插件的基本使用

    官网地址:https://www.jstree.com/ json返回参数格式:推荐第二种方式 不需要在重新拼接返回格式 不刷新页面重新初始化 jstree时使用:$.jstree.destroy() ...

  6. swfit-学习笔记(表UITableView的简单使用)

    /*使用与Object-C基本类似,只做简单地使用,创建表及其设置数据源和代理*/ import UIKit class ViewController: UIViewController,UITabl ...

  7. java多线程通信 例子

    package com.cl.www.thread; public class NumberHolder { private Integer number = 0; // 增加number publi ...

  8. Dockerfile初探

    git上的asp.net samples工程已经写好了docker file,内容是如下   //任何dockersfile都要以FORM开头,约定是用大写. FROM microsoft/aspne ...

  9. bzoj1251

    1251: 序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 3776  Solved: 1581[Submit][Status][Discu ...

  10. Tomcat内存溢出的三种情况及解决办法分析

    Tomcat内存溢出的原因 在生产环境中tomcat内存设置不好很容易出现内存溢出.造成内存溢出是不一样的,当然处理方式也不一样. 这里根据平时遇到的情况和相关资料进行一个总结.常见的一般会有下面三种 ...