generator的作用

使用mybatis框架,在初始项目或修改数据库时,相应的要在JAVA项目中去写一些数据模型文件,DAO,映射XML等配置,而这个插件的作用就是自动生成这些文件,以节省大量时间

pom.xml

    <build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<!-- 在控制台打印执行日志 -->
<verbose>true</verbose>
<!-- 重复生成时会覆盖之前的文件-->
<overwrite>true</overwrite>
<configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
</configuration>
</plugin>
</plugins>
</build>

generatorConfig.xml

默认在src/main/resources目录配置这个文件
<?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>
<!-- mysql的jar文件路径 -->
<classPathEntry location="D:\xxx\xxx.jar" />
<context id="Mysql" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressAllComments" value="true" />
<property name="suppressDate" value="true" />
</commentGenerator> <!-- 数据库相关配置 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/test?useSSL=false" userId="root" password="123456"/> <!-- 配置pojo目录 -->
<javaModelGenerator targetPackage="mybatis.pojo" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaModelGenerator> <!-- 配置xml映射目录 -->
<sqlMapGenerator targetPackage="mybatis.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator> <!-- 配置dao目录 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="mybatis.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
</javaClientGenerator> <!-- tableName是数据库中的表名,domainObjectName是生成的JAVA模型名,后面的参数不用改,要生成更多的表就在下面继续加table标签 -->
<table tableName="demo" domainObjectName="demo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
有注释的地方需要改成自己的环境配置

执行
执行命令:mvn mybatis-generator:generate

以上三个文件都是自动生成的


maven(18)-mybatis generator插件的更多相关文章

  1. 利用maven的MyBatis Generator 插件自动创建代码

    1.首先创建Maven工程 2.修改pom.xml文件代码如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xml ...

  2. Eclipse 使用mybatis generator插件自动生成代码

    Eclipse 使用mybatis generator插件自动生成代码 标签: mybatis 2016-12-07 15:10 5247人阅读 评论(0) 收藏 举报 .embody{ paddin ...

  3. Mybatis Generator插件和PageHelper使用

    最近,开始接触web项目开发,项目使用springboot和mybatis,以前一直以为开发过程中实体类,mybatis的xml文件都需要自己手动的去创建. 同事推荐说Mybatis Generato ...

  4. Mybatis-Generator_学习_02_使用Mapper专用的MyBatis Generator插件

    源码见:https://github.com/shirayner/tk-mybatis-generator 一.要点 二.具体实现 1.项目结构 2.配置 pm.xml <?xml versio ...

  5. Mybatis分页-利用Mybatis Generator插件生成基于数据库方言的分页语句,统计记录总数 (转)

    众所周知,Mybatis本身没有提供基于数据库方言的分页功能,而是基于JDBC的游标分页,很容易出现性能问题.网上有很多分页的解决方案,不外乎是基于Mybatis本机的插件机制,通过拦截Sql做分页. ...

  6. Myeclipse2014添加mybatis generator插件

    Myeclipse2014把mybatis generator插件直接放在dropins文件夹下,重启后不能成功安装mybatis插件. 既然离线安装不成功,可以选择在线安装 1.选择 Help-&g ...

  7. mybatis generator 插件安装及使用

    现在Mybatis特别火,但是在开发中却要经常写实体类和配置文件,会不会特别烦人,所以可以利用Mybatis的代码生成插件来生成这部分代码: 1,打开eclipse,点击Help>Softwar ...

  8. Eclipse MyBatis Generator插件安装

    目录 Eclipse MyBatis Generator插件安装 Eclipse MyBatis Generator插件安装 1.进入Eclipse Marketplace [Help] -> ...

  9. maven项目重构-使用了mybatis generator插件

    1.在worksapce下,dos窗口输入spring init -g=com.briup.apps -a=poll3 -d=mysql,mybatis,web poll3 2.下载依赖,cd到pol ...

随机推荐

  1. (转)错误"因为数据库正在使用,所以无法获得对数据库的独占访问权"的解决方案

    引发原因:是因为我在还原数据库的时候,还有其他的用户正在使用数据库,所以就会出现以上提示. 解决方法:1,设置数据库在单用户模式下工作.设置方法:在需要还原的数据库上右击,在右键菜单命令上选择&quo ...

  2. vue遇见better-scroll

    better-scroll better-scroll 是一款重点解决移动端(现已支持 PC 端)各种滚动场景需求的插件.它的核心是借鉴的 iscroll 的实现,它的 API 设计基本兼容 iscr ...

  3. 关于dubbo调度时出现Request processing failed; nested exception is com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method insertTestTb in the service cn.cuibusi.core.service.TestTbService.的解决办法

    在用dubbo跨项目调度service时出现如下错误: 错误原因:pojo没有实现序列化 解决方法:在pojo实现序列化接口即可

  4. nginx设置开机自启动

    每次启动nginx服务都需要到安装目录下的/sbin下面,感觉挺麻烦的. 下面介绍一下如何在Linux(CentOS)系统上,设置nginx开机自启动. 1 用脚本管理nginx服务 第一步:在/et ...

  5. 什么是SharePoint?

    在聊SharePoint开发之前,有必要说下什么是SharePoint. 在我工作的过程中,经常遇到客户对SharePoint不太了解的情况.有客户说,SharePoint太烂了,DropBox能做到 ...

  6. UVM_INFO

    文件:src/ch3/section3.5/3.5.6/get/my_model.sv 21 function void my_model::build_phase(uvm_phase phase); ...

  7. apache Header set Cache-Control

    设置静态页面的缓存最大值 在.htaccess中添加下面的代码 <FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$"> Hea ...

  8. 微信小程序button选中改样式-实现单选/多选

    小程序实现多button单选/多选 红色为选中状态 单选 多选 ①wxss /* pages/button-select/button-select.wxss */ .button_container ...

  9. [LeetCode]Find Bottom Left Tree Value

    Find Bottom Left Tree Value: Given a binary tree, find the leftmost value in the last row of the tre ...

  10. NIO与Socket

    一.Socket 的使用 1.单线程Socket的使用 /** * 单线程版本 * 问题描述:只能服务单个客户端 * 解决方案:多线程版本 */ public class Socket_V1 { pu ...