Mybatis使用Mybatis-generator插件及配置(数据库逆向工程)
Mybatis使用Mybatis-generator插件
首先在POM.xml文件添加架包,我这里用的是SpringBoot,所以用的也是SpringBoot架包,最少要mybatis,generator,mysql
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2 </version>
</dependency> <dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<!--最好添加一个线程池-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.3</version>
</dependency>
导入插件依赖包后,在plugins内配置
<!--配置mybatis自动生成代码generator-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>mybatis generator</id>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<!--允许移动生成文件-->
<verbose>true</verbose>
<!--允许自动覆盖文件-->
<overwrite>true</overwrite>
<configurationFile>
src/main/resources/mybatis-generator.xml
</configurationFile>
</configuration>
</plugin>
然后在resources包下创建mybatis-generator.xml配置文件(注意名字一定一模一样,我就是把-写成了_弄了大半天)
首先在JdbcConnection的标签内配置类,url,userId,pwd等,javaModelGenerator中配置java Bean对应的路径,
sqlMapgenerator的映射路径,mybatis的mapping映射;javaClientGenerator里填写dao层的路径,最后配置数据库的表table,最好加上enableCountByExample="false" ,enableUpdateByExample="false"enableDeleteByExample="false" enableSelectByExample="false"selectByExampleQueryId="false"。
<?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="DB2Tables" targetRuntime="MyBatis3">
<!--数据库连接地址账号密码-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://127.0.0.1:3306/mssc"
userId="root"
password="111111">
</jdbcConnection> <javaTypeResolver >
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!--生成Model(DataObject类)存放的位置-->
<javaModelGenerator targetPackage="com.dspro.dataobject" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!--生成映射文件存放位置-->
<sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!--生成Dao类文件存放-->
<!--客户端代码,生成易于使用的针对Model对象和XML配置文件的代码-->
<!--type="ANNOTATEDMAPPER" 生成javaModel和基于注解的Mapper对象-->
<!--type="MIXEDMAPPER",生成基于注解的javaModel和相应的Mapper对象-->
<!--type="XMLMAPPER",生成SQLMAP XML文件和独立的Mapper接口-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.dspro.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator> <!--<table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" >-->
<!--<property name="useActualColumnNames" value="true"/>-->
<!--<generatedKey column="ID" sqlStatement="DB2" identity="true" />-->
<!--<columnOverride column="DATE_FIELD" property="startDate" />-->
<!--<ignoreColumn column="FRED" />-->
<!--<columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" />-->
<!--</table>-->
<table tableName="user_info" domainObjectName="UserDO"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">
</table>
<table tableName="user_password" domainObjectName="UserPasswordDo"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"></table> </context>
</generatorConfiguration>
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"
这几个配置了之后就不会产生example类,不然新版本会产生一个example文件。
上面是我自己的配置,需要官方配置xml文件的官方配置
然后(IDEA)run-->edit configurations,点击"+"添加maven,在Command line处填写
mybatis-generator:generate
命令,
点击OK,然后run。 错误:
"POM for xxx is missing, no dependency information available"
The POM for org.eclipse.m2e:lifecycle-mapping:jar:1.0. is missing, no dependency information available
在POM里添加:
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<versionRange>[1.2,)</versionRange>
<goals>
<goal>enforce</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
Mybatis使用Mybatis-generator插件及配置(数据库逆向工程)的更多相关文章
- Mybatis分页-利用Mybatis Generator插件生成基于数据库方言的分页语句,统计记录总数 (转)
众所周知,Mybatis本身没有提供基于数据库方言的分页功能,而是基于JDBC的游标分页,很容易出现性能问题.网上有很多分页的解决方案,不外乎是基于Mybatis本机的插件机制,通过拦截Sql做分页. ...
- Springboot 系列(十一)使用 Mybatis(自动生成插件) 访问数据库
1. Springboot mybatis 介绍 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数获取 ...
- Mybatis Generator插件和PageHelper使用
最近,开始接触web项目开发,项目使用springboot和mybatis,以前一直以为开发过程中实体类,mybatis的xml文件都需要自己手动的去创建. 同事推荐说Mybatis Generato ...
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
- JavaWeb_(Mybatis框架)MyBatis Generator简单入门
官方文档 传送门 下载地址 传送门 MyBatis Generator(MBG)简介: MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器.它将为 ...
- mybatis generator 插件安装及使用
现在Mybatis特别火,但是在开发中却要经常写实体类和配置文件,会不会特别烦人,所以可以利用Mybatis的代码生成插件来生成这部分代码: 1,打开eclipse,点击Help>Softwar ...
- Eclipse 使用mybatis generator插件自动生成代码
Eclipse 使用mybatis generator插件自动生成代码 标签: mybatis 2016-12-07 15:10 5247人阅读 评论(0) 收藏 举报 .embody{ paddin ...
- Mybatis-Generator_学习_02_使用Mapper专用的MyBatis Generator插件
源码见:https://github.com/shirayner/tk-mybatis-generator 一.要点 二.具体实现 1.项目结构 2.配置 pm.xml <?xml versio ...
- maven项目重构-使用了mybatis generator插件
1.在worksapce下,dos窗口输入spring init -g=com.briup.apps -a=poll3 -d=mysql,mybatis,web poll3 2.下载依赖,cd到pol ...
随机推荐
- 5.JavaCC官方入门指南-概述
一.前言 在最开始使用JavaCC的时候,从网上查询了许多资料,但是网上的资料水平是参差不齐的,走了许多弯路,不得已自己查阅了英文版官网文档.令我伤心的是最后我回过头来再看那些博客资料时,发现其实 ...
- Python入门基础学习(列表/元组/字典/集合)
Python基础学习笔记(二) 列表list---[ ](打了激素的数组,可以放入混合类型) list1 = [1,2,'请多指教',0.5] 公共的功能: len(list1) #/获取元素 lis ...
- DRF的基本使用(一)
本帖最后由 杰哥,我就服你 于 2018-12-20 13:22 编辑 Django rest framework(DRF) D:是一个用于构建Web API强大又灵活的框架,基于Django框架二次 ...
- 配置Ngnix1.15.11+php5.4出现502 Bad Gateway问题
今天在调试Ngnix1.15.11+php5.4网站时候,因为网站数据和并发过大,出现502 Bad Gateway问题,所以记下笔记. 只需要修改php-fpm.conf的request_termi ...
- day48_9_9 前端之javascript与jQuary
一.BOM与DOM BOM(Browser Object Model)是指浏览器对象模型,它使 JavaScript 有能力与浏览器进行“对话. DOM (Document Object Model) ...
- [C2P3] Andrew Ng - Machine Learning
##Advice for Applying Machine Learning Applying machine learning in practice is not always straightf ...
- Python学习笔记5 【转载】基本矩阵运算_20170618
需要 numpy 库支持 保存链接 http://www.cnblogs.com/chamie/p/4870078.html 1.numpy的导入和使用 from numpy import *;#导入 ...
- Jenkins根据svn版本号进行构建
在svn版本url后面加上“@svn版本号”,如@2105 原文:https://blog.csdn.net/jlminghui/article/details/40426849
- win10,anconda, python3.6安装dlib19.17
目的和经验: 几个月前在笔记本上安过一次,按着教程用cmake编译其实也蛮简单的,不过当初忘了收藏了.现在换了台机子需要重新安装一遍,奈何之前的帖子找不到了. pypi 网站上有19.8.whl,如果 ...
- CF1249F Maximum Weight Subset
CF1249F Maximum Weight Subset 洛谷评测传送门 题目描述 You are given a tree, which consists of nn vertices. Reca ...