Mybatis generator(复制粘贴完成)
命令行模式
1、java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml
2、Maven plugin(mybatis-generator-maven-plugin) 常用
2.1、mvn mybatis-generator:generate
2.2、${basedir}/src/main/resources/generatorConfig.xml 默认读取这个文件,所以新建项目的话,直接添加这个文件即可。
3、java 程序
4、Ant Task 少用
generatorConfiguration
context
1、jdbcConnection
2、javaModelGenerator
3、sqlMapGenerator
4、javaClientGenerator(注解方式/xml方式/混合方式),简单的用注解方式,用到一些例子的话用xml方式
5、table
生成时可以使用的插件(内置插件都在org.mybatis.generator.plugins中)
1、FluentBuilderMethodsPlugin
2、ToStringPlugin
3、SerializablePlugin
4、RowBoundsPlugin(分页有用)
...
使用生成对象
1、简单操作,直接使用生成的xxxMapper的方式
2、复杂查询,使用生成的xxxExample对象
说了那么多,具体操作可以直接做以下2个步骤即可。
1、在springboot的启动类上,添加如下代码
2、加上一个配置文件
使用了java代码的方式进行生成代码
@SpringBootApplication
public class PointReportApplication implements CommandLineRunner
{ public static void main(String[] args) {
SpringApplication.run(PointReportApplication.class, args);
} @Override
public void run(String... strings) throws Exception {
generateArtifacts();
} private void generateArtifacts() throws Exception {
List<String> warnings = new ArrayList<>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(
this.getClass().getResourceAsStream("/generatorConfig.xml"));
DefaultShellCallback callback = new DefaultShellCallback(true);
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
myBatisGenerator.generate(null);
} }
创建一个xml文件,文件名称为: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="H2Tables" targetRuntime="MyBatis3Simple">
<plugin type="org.mybatis.generator.plugins.FluentBuilderMethodsPlugin" />
<plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" /> <jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://119.23.209.247/test?truecharacterEncoding=UTF-8"
userId="root"
password="asd222030">
</jdbcConnection> <javaModelGenerator targetPackage="com.ky.pointreport.dto"
targetProject="./src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator> <sqlMapGenerator targetPackage="mybatis.mapper"
targetProject="./src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator> <javaClientGenerator type="XMLMAPPER"
targetPackage="com.ky.pointreport.dao"
targetProject="./src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<table tableName="jd_ky_consume_detail" domainObjectName="jdKyConsumeDetail" >
<generatedKey column="id" sqlStatement="CALL IDENTITY()" identity="true" />
</table>
</context>
</generatorConfiguration>
Mybatis generator(复制粘贴完成)的更多相关文章
- MyBatis Generator Example.Criteria 查询条件复制
背景: 我们在开发中使用MyBatis Generator生成的 XxxExample查询时,咋添加 or 查询时候,可能两个 Example.Criteria 对象的条件存在交集,即多个查询条件是相 ...
- MyBatis Generator 详解
MyBatis Generator中文文档 MyBatis Generator中文文档地址:http://mbg.cndocs.tk/ 该中文文档由于尽可能和原文内容一致,所以有些地方如果不熟悉,看中 ...
- MyBatis Generator 详解 【转来纯为备忘】
版权声明:版权归博主所有,转载请带上本文链接!联系方式:abel533@gmail.com 目录(?)[+] MyBatis Generator中文文档 运行MyBatis Generator X ...
- mybatis Generator配置文件详解
这里按照配置的顺序对配置逐个讲解,更细的内容可以配合中文文档参照. 1. 配置文件头 <?xml version="1.0" encoding="UTF-8&quo ...
- MyBatis Generator自动生成的配置及使用
注意:文件名不能有中文字符,不然不能自动生成 找到MyBatis Generator.rar\MyBatis Generator\eclipse里的features和plugins文件,把这两个文件复 ...
- 使用MyBatis Generator自动创建代码
SSM框架--使用MyBatis Generator自动创建代码 1. 目录说明 使用自动生成有很多方式,可以在eclipse中安装插件,但是以下将要介绍的这种方式我认为很轻松,最简单,不需要装插件, ...
- mybatis.generator.configurationFile
mybatis.generator.configurationFile 有一个更好的配置方法,可以不用在generateConfig.xml里面写死驱动的地址:如果你的mybatis连接也是在pom. ...
- MyBatis Generator For Eclipse 插件安装
由于在ORM框架MyBatis中,实现数据表于JavaBean映射时,配置的代码比较的复杂,所以为了加快开发的效率,MyBatis官方提供了一个Eclipse的插件, 我izuoyongjiushis ...
- 使用Mybatis Generator插件自动生成映射文件(cmd无法进入文件,dns服务器对区域没有权威等问题)遇到问题
使用Mybatis Genertor插件自动生MyBatis所需要的DAO接口,实体模型类,Mapping映射文件,将生成的代码赋值到项目工程中即可. 有命令行,Eclipse插 ...
随机推荐
- CircleCI 与持续集成
CircleCI 入门 最近在完成老师的作业:使用 CircleCI 进行持续集成,现将过程书写下来,与大家一起学习进步. A. What is CircleCI? 1. 什么是持续集成 持续集成(C ...
- WampServer的安装
首先安装好Microsoft Visual C++ 然后再安装WampServer 安装过程很简单 错误解决 运行后为黄色图标(成功运行应该为绿色图标) 解决办法: 1.80端口是否被占用 你的80端 ...
- Docker 快速安装&搭建 Ngnix 环境,并配置反向代理
欢迎关注个人微信公众号: 小哈学Java, 文末分享阿里 P8 高级架构师吐血总结的 <Java 核心知识整理&面试.pdf>资源链接!! 个人网站: https://www.ex ...
- 洛谷 P3128 [USACO15DEC]最大流Max Flow
题目描述 \(FJ\)给他的牛棚的\(N(2≤N≤50,000)\)个隔间之间安装了\(N-1\)根管道,隔间编号从\(1\)到\(N\).所有隔间都被管道连通了. \(FJ\)有\(K(1≤K≤10 ...
- php微信公众号开发简单记录
开发前准备:1.服务器 2.微信公众号测试号(有真实的账号更好) 测试号申请地址:https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/lo ...
- thinkphp5.1composer引入第三方类库使用注意
下面以引入phpspider为例子: composer引入: composer require owner888/phpspider 这时在vender目录下会多出一个owner888目录,里面就有我 ...
- 关于map 及 map 骚操作
关于map这个东西 很冷门.................. 但是,这个博客带你稍微了解一下map: map用法:一般当作一个下表无穷大的数组 关于它的骚操作:map的鬼畜用法,可以 ...
- ng2学习--pipe使用
We use our custom pipe the same way we use built-in pipes.(自定义Pipe和API里自带的Pipe使用方式一致) We must includ ...
- C# Repeater 嵌套
<table class="table table-bordered table-fixed"> <thead> <tr> <th wid ...
- C# 的两种debug 方法
第一种:需要把调试方法改成debug代码用 #if DEBUG 包裹 using System; using System.Collections.Generic; using System.Text ...