mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置
mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置
==============================
蕃薯耀 2018年3月14日
http://www.cnblogs.com/fanshuyao/
一、使用Maven方式引入Mybatis依赖Jar包(版本号自己改或定义)
- <properties>
- <spring.version>4.3.13.RELEASE</spring.version>
- <mybatis.version>3.4.6</mybatis.version>
- <mybatis.spring.version>1.3.1</mybatis.spring.version>
- <mybatis.generator.version>1.3.6</mybatis.generator.version>
- <junit.version>4.12</junit.version>
- </properties>
- <!-- mybatis-->
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- <version>${mybatis.version}</version>
- </dependency>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis-spring</artifactId>
- <version>${mybatis.spring.version}</version>
- </dependency>
- <dependency>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-core</artifactId>
- <version>${mybatis.generator.version}</version>
- <scope>provided</scope>
- </dependency>
二、加入文件生成xml配置文件
直接在项目文件夹下建立xml配置文件:mybatis-generator.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">
- <!-- 配置文件信息见:http://www.mybatis.org/generator/configreference/xmlconfig.html -->
- <generatorConfiguration>
- <!-- 配置数据库信息 -->
- <context id="mysql" targetRuntime="MyBatis3">
- <commentGenerator>
- <!-- 设置不生成注释 suppressAllComments :When the property is true, no comments will be added to any generated element.-->
- <property name="suppressAllComments" value="true" />
- </commentGenerator>
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
- connectionURL="jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull"
- userId="root"
- password="root">
- </jdbcConnection>
- <javaTypeResolver>
- <property name="forceBigDecimals" value="false" />
- </javaTypeResolver>
- <!-- 指定JavaBean生成的位置,.\src表示直接在项目的src目录下生成 -->
- <javaModelGenerator targetPackage="com.lqy.ssm.bean" targetProject=".\src\main\java">
- <property name="enableSubPackages" value="true" />
- <property name="trimStrings" value="true" />
- </javaModelGenerator>
- <!-- 指定sql映射文件生成的位置 -->
- <sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
- <property name="enableSubPackages" value="true" />
- </sqlMapGenerator>
- <!-- 指定dao接口生成的位置 -->
- <javaClientGenerator type="XMLMAPPER" targetPackage="com.lqy.ssm.dao" targetProject=".\src\main\java">
- <property name="enableSubPackages" value="true" />
- </javaClientGenerator>
- <!-- 指定每个table表生成的策略 -->
- <!-- domainObjectName可省略 -->
- <table tableName="user" domainObjectName="User"
- enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false"></table>
- <table tableName="user_ext"
- enableSelectByExample="false" enableDeleteByExample="false" enableCountByExample="false" enableUpdateByExample="false"></table>
- </context>
- </generatorConfiguration>

把数据库连接信息修改为自己的数据库连接。
三、创建生成文件的代码类:MybatisGenerator.java,内容如下:
官网代码见:http://www.mybatis.org/generator/running/runningWithJava.html
- 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 MybatisGenerator {
- public static void main(String[] args) throws Exception {
- List<String> warnings = new ArrayList<String>();
- boolean overwrite = true;
- File configFile = new File("mybatis-generator.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);
- }
- }
其中File configFile = new File("mybatis-generator.xml");就是读取自己的配置文件,如果命名不一致,需要改为一致。

四、最后运行MybatisGenerator方法生成文件,然后F5刷新项目,文件就直接生成。
==============================
蕃薯耀 2018年3月14日
http://www.cnblogs.com/fanshuyao/
mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置的更多相关文章
- eclipse中mybatis generator插件的安装与使用,实现自动生成代码
git地址:https://github.com/mybatis/generator 下载后解压: 选择任意一个版本的jar放到eclipse的features目录下即可 选择任意一个版本的jar放到 ...
- SpringBoot(十一):springboot2.0.2下配置mybatis generator环境,并自定义字段/getter/settetr注释
Mybatis Generator是供开发者在mybatis开发时,快速构建mapper xml,mapper类,model类的一个插件工具.它相对来说对开发者是有很大的帮助的,但是它也有不足之处,比 ...
- 使用MyBatis Generator 1.3.7自动生成代码
MyBatis Generator是一款mybatis自动代码生成工具,可以通过配置后自动生成文件. MyBatis Generator有几种方法可以生成代码,下面是其中一种. 一.官网下载 MyB ...
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
原文链接 我们这一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池 ...
- IDEA Maven Mybatis generator 自动生成代码
IDEA Maven Mybatis generator 自动生成代码 一.安装配置maven以及在Idea中配置maven 安装过程步骤可以看上面的博文,里面介绍得很详细. 二.建数据表 DROP ...
- Eclipse 使用mybatis generator插件自动生成代码
Eclipse 使用mybatis generator插件自动生成代码 标签: mybatis 2016-12-07 15:10 5247人阅读 评论(0) 收藏 举报 .embody{ paddin ...
- IDEA Maven Mybatis generator 自动生成代码(实例讲解)(转)
IDEA Maven Mybatis generator 自动生成代码(实例讲解) MyBatis Generator • 简称MBG,是一个专门为MyBatis框架使用者定制的代码生成器,可以快速的 ...
- IDEA使用mybatis generator自动生成代码
主要就三步: 1.pom 文件中引入jar包并配置 build 属性 <dependencies> <!-- 自动生产mapper Begin! --> <depende ...
- spring boot集成mybatis(3) - mybatis generator 配置
Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...
随机推荐
- MongoDB 比较适用哪些业务场景?
在云栖社区上发起了一个 MongoDB 使用场景及运维管理问题交流探讨的技术话题,有近5000人关注了该话题讨论,这里就 MongoDB 的使用场景做个简单的总结,谈谈什么场景该用 MongoDB ...
- webpack4--热更新
所谓热更新,就是在浏览器能同步刷新你的代码.webpack 热更新依赖 webpack-dev-server.具体实现步骤如下: 1.局部安装依赖 webpack-dev-server npm ins ...
- label文字居中
height: height,//"20px" "line-height": height, autosize:true, &qu ...
- JavaScript prototype背后的工作原理
首先从一个函数说起 function fn1(name, age) { this.name = name; this.age = age; this.say = function() { alert( ...
- ubuntu安装mxnet GPU版本
安装mxnet GPUsudo pip install mxnet-cu80==1.1.0 推荐pip安装mxnet,土豪gpu版本: pip install mxnet-cu90==1.0.0 豪华 ...
- Android 耳机插入过程分析
Android 耳机插入过程分析 参考链接: https://www.jianshu.com/p/d82a8dabb3e7 初始化: 10-26 07:40:43.932 1414 1414 I Sy ...
- 第三百八十三节,Django+Xadmin打造上线标准的在线教育平台—第三方模块django-simple-captcha验证码
第三百八十三节,Django+Xadmin打造上线标准的在线教育平台—第三方模块django-simple-captcha验证码 下载地址:https://github.com/mbi/django- ...
- 性能优化系列三:JVM优化
一.几个基本概念 GCRoots对象都有哪些 所有正在运行的线程的栈上的引用变量.所有的全局变量.所有ClassLoader... 1.System Class.2.JNI Local3.JNI Gl ...
- JUnit4参数化测试实例
在JUnit中,可以同时使用@RunWith 和 @parameter 注解来为单元测试传递参数. 注意: 在Eclipse中因为版本问题,可能无法使用@parameters(name = " ...
- e565. 关闭的时候隐藏窗口
By default, when the close button on a frame is clicked, nothing happens. This example shows how to ...