Maven项目创建mybatis generator步骤

简介: mybatis generator mysql
+关注继续查看

Maven项目创建mybatis generator需要注意事项:


1.参考资料中说的

<dependency>

<groupId>org.mybatis.generator</groupId>


<artifactId>mybatis-generator</artifactId>


<version>1.3.2</version>


</dependency>
这个没必要使用,使用了会一直下载不到jar 报错

2.

mysqlmysql-connector-java的jar如果是使用6.0.5版本会报错,建议降低版本到5.1.39(本地mysql server是5.7.18)

3.

generatorConfig.xml这个文件需要配对targetProject路径

4.pom文件:


<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mybatis.test</groupId>
<artifactId>test-mybatis-generator</artifactId>
<version>1.0-SNAPSHOT</version>


<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>

</dependencies>


<build>
<finalName>xxx</finalName>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>

</project>






5.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>
<!-- 指定数据连接驱动jar地址 -->
<classPathEntry
location="/Users/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar" />
<!-- 一个数据库一个context -->
<context id="context" defaultModelType="flat" targetRuntime="MyBatis3">
<!-- 注释 -->
<commentGenerator>
<property name="suppressAllComments" value="false" /><!-- 是否取消注释 -->
<property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳 -->
</commentGenerator>
<!-- jdbc连接 --> <!--jdbc:mysql://xxxxxxx:8406/CL_DEMO?useUnicode=true&amp;characterEncoding=UTF-8-->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/cms?useUnicode=true&amp;characterEncoding=UTF-8" userId="root"
password="newpass" />

<!-- 类型转换 -->
<javaTypeResolver>
<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>

<!-- 生成实体类地址 -->
<javaModelGenerator targetPackage="com.cd.dao.pojo"
targetProject="src/main/java">
<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
<property name="enableSubPackages" value="false" />
<!-- 是否针对string类型的字段在set的时候进行trim调用 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>

<!-- 生成mapxml文件 -->
<sqlMapGenerator targetPackage="com.cd.dao.mapper"
targetProject="src/main/java">
<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>

<!-- 生成mapxml对应client,也就是接口dao -->
<javaClientGenerator targetPackage="com.cd.dao.mapper"
targetProject="src/main/java" type="XMLMAPPER">
<!-- 是否在当前路径下新加一层schema,eg:fase路径com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>

<table schema="cms" tableName="application_permission"
domainObjectName="ApplicationPermission" selectByExampleQueryId="false"
enableCountByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" enableUpdateByExample="false"
enableDeleteByPrimaryKey="false" />


</context>


</generatorConfiguration>





6.参考资料:

http://www.tuicool.com/articles/NBnUr2E

http://www.cnblogs.com/smileberry/p/4145872.html

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
27天前
|
XML Java 数据库连接
Mybatis使用generator逆向工程生成器生成entity、mapper、.xml模版类
今天将表建好了,但是一个一个的建实体类、Mapper接口、Mapper.xml文件就十分的麻烦,所以我就想到了MyBatis逆向,今天就操作一把!这里我们采用maven来进行操作。
|
5月前
|
XML SQL 前端开发
不是吧,你还在使用MyBatis Generator?试试这个工具吧
在企业软件开发过程中,大多数时间都是面向数据库表的增删改查开发。通过通用的增删改查代码生成器,可以有效的提高效率,降低成本;把有规则的重复性劳动让机器完成,解放开发人员。
|
7月前
|
XML Oracle Java
mybatis generator(MyBatis的逆向工程)
mybatis generator(MyBatis的逆向工程)
74 0
mybatis generator(MyBatis的逆向工程)
|
8月前
|
Java 数据库连接 数据库
MyBatis逆向工程 Generator
MyBatis逆向工程 Generator
MyBatis逆向工程 Generator
|
10月前
|
SQL Java 关系型数据库
解决 Mybatis Generator由表字段使用关键字导致的异常方案
解决 Mybatis Generator由表字段使用关键字导致的异常方案
89 0
|
12月前
|
消息中间件 运维 Java
【Mybatis】Mybatis generator如何修改Mapper.java文件
我写的代码生成插件Gitee地址同样是在扩展 Mybatis generator插件的时候,有这样一个需求是需要在生成的,那么 如何修改Mapper.java文件? 跟着Mybatis generator 源码去找一找 哪里可以扩展
|
Java 数据库连接 mybatis
Java:MyBatis Generator自动生成代码
Java:MyBatis Generator自动生成代码
115 0
|
消息中间件 运维 Java
【Mybatis】Mybatis generator自动生成插件如何修改Mapper.xml 的命名空间namespace
这也是在扩展 Mybatis generator 的时候遇到的问题,记录一下; 在上一篇文章 如何继承Mybatis中的Mapper.xml文件很重要的一点就是要让两个Mapper.xml文件的命名空间相同,这样才能够实现继承; 那么既然是自动生成插件,在生成原始 Mapper.xml的时候,我要如何去修改他的命名空间呢? 例如
|
Java 数据库连接 Maven
MyBatis - Mybatis Generator Maven 插件自动生成代码
MyBatis - Mybatis Generator Maven 插件自动生成代码
429 0
|
SQL Java 数据库连接
MyBatis加强(1)~mybatis的代码生成器 Generator
MyBatis加强(1)~mybatis的代码生成器 Generator
185 0
MyBatis加强(1)~mybatis的代码生成器 Generator
推荐文章
更多
推荐镜像
更多