使用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的更多相关文章

  1. IDEA 使用generator逆向工程生成pojo,mapper

    1.新建立一个MAVEN项目 2.在pom.xml增加配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns: ...

  2. 在IDEA中使用MyBatis Generator逆向工程生成代码

    本文介绍一下用Maven工具如何生成Mybatis的代码及映射的文件. 一.配置Maven pom.xml 文件 在pom.xml增加以下插件: <build> <finalName ...

  3. Mybatis Generator自动生成的mapper只有insert方法

    – Mybatis Generator 生成的mapper只有insert方法 – 首先检查generatorConfig.xml中table项中的属性 enableSelectByPrimaryKe ...

  4. java web(七): mybatis的动态sql和mybatis generator自动生成pojo类和映射文件

    前言: MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其它类似框架的经验,你就能体会到根据 不同条件拼接 SQL 语句的痛苦.例如拼接时要确保不能忘记添加必要的空格,还 ...

  5. Mybatis根据数据库中的表自动生成Bean对象与Mapper文件 (小白式教程)

    示例IDE采用 IDEA //**********************华丽的分割线****************// 1.新建一个java项目-->在Src目录下创建3个包(Package ...

  6. 逆向工程生成的Mapper.xml以及*Example.java详解

    逆向工程生成的接口中的方法详解 在我上一篇的博客中讲解了如何使用Mybayis逆向工程针对单表自动生成mapper.java.mapper.xml.实体类,今天我们先针对mapper.java接口中的 ...

  7. 整合mybaties 逆向生成 pojo mapper.xml

    第一步:配置properties 第二步:放入generatorConfig.xml文件  在总目录下  这个是生成工具 第三步:放入工具类,自动生成用的,  pom里面要加入6个依赖 第四步:运行u ...

  8. idea 中使用Mybatis Generator逆向工程生成代码

    通过MAVEN完成 Mybatis 逆向工程 1. POM文件中添加插件 在 pom 文件的build 标签中 添加 plugin 插件和 数据库连接 jdbc 的依赖. <build> ...

  9. 2019-04-28 Mybatis generator逆向工程生成的Example代码分析

    今天主要对Mybatis generator生成的DAO层等进行分析,讲解Example类的使用和扩展 1.先在数据库建表 CREATE TABLE `department` ( `fid` ) NO ...

随机推荐

  1. win8.1无法安装安装.net framework 3.5 解决办法【转】

    安装流程1.以系统管理员开启命令提示符(命令提示字符)2挂载windows8.1异3,在命令提示符下输入Dism /online /enablefeature/featurename:NetFx3 / ...

  2. easyui dialog 按钮动态命名

    1.方法一: /** * grid新增 * 弹框并且获取支付类型 */ function gridAdd() { var dlg = $('#mydialog').dialog({ title : & ...

  3. [Android Memory] 怎样使一个Android应用不被杀死

    转载自: http://blog.sina.com.cn/s/blog_3e3fcadd0100yjo2.html 参考:http://blog.csdn.net/windskier/article/ ...

  4. Java程序员到架构师的推荐阅读书籍

    作为Java程序员来说,最痛苦的事情莫过于可以选择的范围太广,可以读的书太多,往往容易无所适从.我想就我自己读过的技术书籍中挑选出来一些,按照学习的先后顺序,推荐给大家,特别是那些想不断提高自己技术水 ...

  5. Python批量修改文件夹内所有json文件中部分内容

    #coding=utf-8 import os import json #获取目标文件夹的路径 filedir = os.getcwd()+'/ceshi' #获取文件夹中的文件名称列表 filena ...

  6. builder pattern

    design patterns 结合书本和这个网站的这个系列的文章来看: https://www.tutorialspoint.com/design_pattern/builder_pattern.h ...

  7. Java Web---登录验证和字符编码过滤器

    什么是过滤器? 在Java Web中,过滤器即Filter.Servlet API中提供了一个Filter接口(javax.servlet.Filter).开发web应用时,假设编写的Java类实现了 ...

  8. 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-A ( ZOJ 3819 ) Average Score

    Average Score Time Limit: 2 Seconds      Memory Limit: 65536 KB Bob is a freshman in Marjar Universi ...

  9. 手游产品经理初探(四)从Buybutton谈玩家付费

    付费模块一直是游戏中最最重要的一块,那么今天我们从玩家的角度来解说哪种方式付费更迎合玩家的心理.我还是着重从我做的Casino类型游戏说起. 一般来说游戏界面喜欢把付费button放在界面最醒目的位置 ...

  10. The fundamental differences between "GET" and "POST"

    The HTML specifications technically define the difference between "GET" and "POST&quo ...