Mybatis在IDEA中使用generator逆向工程生成pojo,mapper
使用mybatis可以逆向生成pojo和mapper文件有很多种方式,我以前用的是mybtais自带的generator包来生成,连接如下:mybatis自己生成pojo
今天我用了IDEA上使用maven项目来生成pojo和mapper,具体步骤如下
1,先配置pom.xml文件,先配置插件plugin
配置文件如下
<build>
<plugins>
<!-- mybatis逆向工程 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!--配置文件的位置-->
<configurationFile>src/main/resources/Personal-GeneratorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>
2,项目中添加配置文件,如上面所示的配置文件目录位置,在添加personal-generatorconfig.xml文件,然后添加配置文件personal-db.properties,位置结构如图所示:

其中personal-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">
<generatorConfiguration>
<properties resource="Personal-DB.properties"></properties>
<classPathEntry location="${jdbc.driverLocation}" />
<!--classPathEntry location="D:\zngkpt\m2\repository\mysql\mysql-connector-java\5.1.40\mysql-connector-java-5.1.40.jar" /-->
<context id="context1" targetRuntime="MyBatis3"> <commentGenerator>
<!-- 去除自动生成的注释 -->
<property name="suppressAllComments" value="true" />
</commentGenerator> <!-- 数据库连接配置 -->
<jdbcConnection driverClass="${jdbc.driverClass}"
connectionURL="${jdbc.connectionURL}"
userId="${jdbc.userId}"
password="${jdbc.password}" />
<!--jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test"
userId="root"
password="mysql" /--> <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver> <!--配置生成的实体包
targetPackage:生成的实体包位置,默认存放在src目录下
targetProject:目标工程名
-->
<javaModelGenerator targetPackage="com.unisits.zngkpt.common.userprivrman.pojo"
targetProject="src/main/java" /> <!-- 实体包对应映射文件位置及名称,默认存放在src目录下 -->
<sqlMapGenerator targetPackage="com.unisits.zngkpt.common.userprivrman.mapper" targetProject="src/main/java" /> <!-- 配置表
schema:不用填写
tableName: 表名
enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:
去除自动生成的例子
-->
<table schema="" tableName="sys_role" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_permission" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_role_permission" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_user" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="sys_user_role" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="unit_info" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
<table schema="" tableName="unit_type" enableCountByExample="false" enableSelectByExample="false"
enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >
</table>
</context>
</generatorConfiguration>
personal-db.properties的代码如下
jdbc.driverLocation=D:\\zngkpt\\m2\\repository\\com\\microsoft\\sqlserver\\sqljdbc4\\4.0\\sqljdbc4-4.0.jar
jdbc.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.connectionURL=jdbc:sqlserver://127.0.0.1:1434;DatabaseName=db_zngkpt
jdbc.userId=sa
jdbc.password=123456
3,到现在为止,所有的mybatis配置工作已经结束了,开始配置idea来运行生成pojo吧
点击菜单Run->Edit Configuration,然后在弹出窗体的左上角,点击+->maven,会出现下面窗体

然后点击apply,确定,然后run刚才新建的那个maven即可,最后生成的结构如下

指令为:
mybatis-generator:generate -e
Mybatis在IDEA中使用generator逆向工程生成pojo,mapper的更多相关文章
- IDEA 使用generator逆向工程生成pojo,mapper
1.新建立一个MAVEN项目 2.在pom.xml增加配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns: ...
- 在IDEA中使用MyBatis Generator逆向工程生成代码
本文介绍一下用Maven工具如何生成Mybatis的代码及映射的文件. 一.配置Maven pom.xml 文件 在pom.xml增加以下插件: <build> <finalName ...
- Mybatis Generator自动生成的mapper只有insert方法
– Mybatis Generator 生成的mapper只有insert方法 – 首先检查generatorConfig.xml中table项中的属性 enableSelectByPrimaryKe ...
- java web(七): mybatis的动态sql和mybatis generator自动生成pojo类和映射文件
前言: MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架的经验,你就能体会到根据 不同条件拼接 SQL 语句的痛苦.例如拼接时要确保不能忘记添加必要的空格,还 ...
- Mybatis根据数据库中的表自动生成Bean对象与Mapper文件 (小白式教程)
示例IDE采用 IDEA //**********************华丽的分割线****************// 1.新建一个java项目-->在Src目录下创建3个包(Package ...
- 逆向工程生成的Mapper.xml以及*Example.java详解
逆向工程生成的接口中的方法详解 在我上一篇的博客中讲解了如何使用Mybayis逆向工程针对单表自动生成mapper.java.mapper.xml.实体类,今天我们先针对mapper.java接口中的 ...
- 整合mybaties 逆向生成 pojo mapper.xml
第一步:配置properties 第二步:放入generatorConfig.xml文件 在总目录下 这个是生成工具 第三步:放入工具类,自动生成用的, pom里面要加入6个依赖 第四步:运行u ...
- idea 中使用Mybatis Generator逆向工程生成代码
通过MAVEN完成 Mybatis 逆向工程 1. POM文件中添加插件 在 pom 文件的build 标签中 添加 plugin 插件和 数据库连接 jdbc 的依赖. <build> ...
- 2019-04-28 Mybatis generator逆向工程生成的Example代码分析
今天主要对Mybatis generator生成的DAO层等进行分析,讲解Example类的使用和扩展 1.先在数据库建表 CREATE TABLE `department` ( `fid` ) NO ...
随机推荐
- Step by Step 使用HTML5开发一个星际大战游戏(2)
HTML5 Canvas Game: 玩家飞船 本系列博文翻译自以下文章 http://blog.sklambert.com/html5-canvas-game-the-player-ship/ L ...
- system表空间爆满解决方法
分类: Oracle 问题描述: 对数据库做检查,发现system表空间持续占满99%.使用如下语句查看: SQL> select b.tablespace_name "表空间&q ...
- Less使用说明
使用koala编译 Koala 是一款由国人开发的开源预处理语言图形编译工具,目前已支持 Less.Sass.Compass 与CoffeeScript. 目前支持以下系统:Windows,Mac, ...
- pip install py-stringsimjoin error: INCLUDE environment variable is empty
在用pip install py-stringsimjoin的时候报错error: INCLUDE environment variable is empty,后来在网上搜索下了说是需要下载安装VCF ...
- Scala快学笔记(一)
一,基本概念: 1,Scala是一种基于JVM的面向对象和函数式编程语言 2,基本类型:数值类型 ->:Byte,Short,Int,Long,Float,Double和布尔类型:Boolean ...
- Python连接MySQL乱码(中文变问号)
#coding=utf-8 import MySQLdb db = MySQLdb.connect("IP","用户名","密码",&quo ...
- 【后台管理系统】—— Ant Design Pro入门学习&项目实践笔记(三)
前言:前一篇记录了[后台管理系统]目前进展开发中遇到的一些应用点,这一篇会梳理一些自己学习Ant Design Pro源码的功能点.附:Ant Design Pro 在线预览地址. Dashboard ...
- 一种让UITableView的数据从下往上增长的方式
遇到问题 一般来说tableview的数据都是从上往下增长,如下图所示(先是aaa出现在表格列表的最顶部,然后bbb出现在aaa的下面,以此类推) 但是如果我们想反向这个过程该怎么做呢?如下图所示(先 ...
- 开源框架Quartz动态加入、改动和删除定时任务 (二)
貌似每次回过头去看之前写的一些东西,总感觉不是非常完美~~虽说不做完美人.但也要做完美事!这次主要是针对Quartz的动态维护和Spring集成.简单粗暴一点,直接上代码,有什么不了解留言交流 先来一 ...
- [转]SQL Server 性能调优(内存)
存储引擎自调整 sql server 是如何分配内存的 32bit地址空间的限制 用户模式vas分配和virtualalloc 非boffer pool 分配内存(保留内存) VAS调整 AWE ...