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插 ...
随机推荐
- [Xcode 实际操作]四、常用控件-(13)使用UIWebView控件加载网页
目录:[Swift]Xcode实际操作 本文将演示网页视图的使用. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit class ViewC ...
- LaTeX使用心得
LaTeX是一个功能强大的,开源的排版工具. 最近教练让我们做课件,我做数论,鉴于LaTeX的数学公式功能强大(而MS办公软件的数学公式简直就是个LJ)和我的学习精神,我决定用LaTeX写课件. 在一 ...
- 【常见Web应用安全问题】
Web应用程序的安全性问题依其存在的形势划分,种类繁多,这里不准备介绍所有的,只介绍常见的一些. 常见Web应用安全问题安全性问题的列表: 1.跨站脚本攻击(CSS or XSS, Cross Sit ...
- bzoj5506:[gzoi2019]旅行者
传送门 正反两边dijkstra染色,然后枚举一下边,求出最小值就好啦 代码: #include<cstdio> #include<iostream> #include< ...
- asddf
https://docs.saltstack.com/en/getstarted/fundamentals/index.html https://pypi.org/simple/cherrypy/ 安 ...
- 洛谷P4018 Roy&October之取石子
题目背景 \(Roy\)和\(October\)两人在玩一个取石子的游戏. 题目描述 游戏规则是这样的:共有\(n\)个石子,两人每次都只能取\(p^k\)个(\(p\)为质数,\(k\)为自然数,且 ...
- 洛谷P3195||bzoj1010 [HNOI2008]玩具装箱TOY
洛谷P3195 bzoj1010 设s数组为C的前缀和 首先$ans_i=min_{j<i}\{ans_j+(i-j-1+s_i-s_j-L)^2\}$ (斜率优化dp)参考(复读)https: ...
- onbeforeunload与onunload事件
Onunload,onbeforeunload都是在刷新或关闭时调用,可以在<script>脚本中通过 window.onunload来指定或者在<body>里指定.区别在于o ...
- @SessionAttribute使用详解
@SessionAttribute使用详解 @ModelAttribute注解作用在方法上或者方法的参数上,表示将被注解的方法的返回值或者是被注解的参数作为Model的属性加入到Model中,然后 ...
- mediawiki登录时第一次会跳回登录页面,第二次才能登录成功
原因是:LocalSetting.php中的$wgServer属性使用的是ip,改为域名后成功解决问题 补充:改为域名后使用ip访问会出现第一次登录跳回登录界面的情况,应该根据实际情况来设置$wgSe ...