springboot mybatis 自动生成代码(maven+IntelliJ IDEA)
1.在pom文件中加入需要的依赖(mybatis-generator-core) 和 插件(mybatis-generator-maven-plugin)
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<!-- mybatis用于生成代码的配置文件 -->
<configuration>
<configurationFile>src/main/resources/configXml/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
2.配置自动生成代码的文件 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> <!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包 -->
<classPathEntry
location="D:\workProjects\springBootMybatis\src\main\resources\lib\mysql-connector-java-5.1.9.jar"/>
<context id="MysqlTables" targetRuntime="MyBatis3">
<!-- 注意这里面的顺序确定的,不能随变更改 -->
<!-- 自定义的分页插件 <plugin type="com.deppon.foss.module.helloworld.shared.PaginationPlugin"/> -->
<!-- 可选的(0 or 1) -->
<!-- 注释生成器 -->
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true" />
</commentGenerator>
<!-- 必须的(1 required) -->
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test_mybatis"
userId="root" password="123456">
</jdbcConnection>
<!-- 可选的(0 or 1) -->
<!-- 类型转换器或者加类型解析器 -->
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer true,把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- 必须的(1 required) -->
<!-- java模型生成器 -->
<!-- targetProject:自动生成代码的位置 -->
<javaModelGenerator targetPackage="com.example.springmybatis.entity"
targetProject="D:\workProjects\springBootMybatis\src\main\java">
<!-- TODO enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- 必须的(1 required) -->
<!-- map xml 生成器 -->
<!-- targetPackage 是 指targetProject下的包-->
<sqlMapGenerator targetPackage="mapper"
targetProject="D:\workProjects\springBootMybatis\src\main\resources">
<property name="enableSubPackages" value="true" />
</sqlMapGenerator>
<!-- 可选的(0 or 1) -->
<!-- mapper 或者就是dao接口生成器 -->
<javaClientGenerator targetPackage="com.example.springmybatis.dao"
targetProject="D:\workProjects\springBootMybatis\src\main\java"
type="XMLMAPPER">
<property name="enableSubPackages" value="true" />
</javaClientGenerator>
<!-- 必须的(1...N) -->
<!-- pojo 实体生成器 -->
<!-- tableName:用于自动生成代码的数据库表;domainObjectName:对应于数据库表的javaBean类名 -->
<!-- schema即为数据库名 可不写 -->
<table tableName="order_info" domainObjectName="OrderInfo"
enableInsert="true" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
enableSelectByExample="false" selectByExampleQueryId="false">
<!-- 忽略字段 可选的(0 or 1) -->
<!-- <ignoreColumn column="is_use" /> -->
<!--//无论字段是什么类型,生成的类属性都是varchar。 可选的(0 or 1) 测试无效 -->
<!-- <columnOverride column="city_code" jdbcType="VARCHAR" /> -->
</table>
</context>
</generatorConfiguration>
注意事项:
- mysql驱动jar包加载,location=“必须是绝对路径”
- 配置文件中 context 节点下的内容,一定要按照以下顺序来(没有的可以不写,有的一定要按照顺序)
- 生成文件路径配置
- 执行生成代码操作(IntelliJ IDEA) 涉及的命令:mybatis-generator:generate -e
- 表结构与生成实体
如有什么不合适的地,烦请个位大佬指出纠正!
springboot mybatis 自动生成代码(maven+IntelliJ IDEA)的更多相关文章
- mybatis自动生成代码插件mybatis-generator使用流程(亲测可用)
mybatis-generator是一款在使用mybatis框架时,自动生成model,dao和mapper的工具,很大程度上减少了业务开发人员的手动编码时间 坐着在idea上用maven构建spri ...
- 【MyBatis】MyBatis自动生成代码查询之爬坑记
前言 项目使用SSM框架搭建Web后台服务,前台后使用restful api,后台使用MyBatisGenerator自动生成代码,在前台使用关键字进行查询时,遇到了一些很宝贵的坑,现记录如下.为展示 ...
- Mybatis 自动生成代码,数据库postgresql
最近做了一个项目,使用Mybatis自动生成代码,下面做一下总结,被以后参考: 一.提前准备: 1.工具类:mybatis-generator-core-1.3.2.jar 2.postgresql驱 ...
- mybatis 自动生成代码(mybatis generator)
pom.xml 文件配置 引入 mybatis generator <properties> <mysql.connector.version>5.1.44</mysql ...
- 自定义Mybatis自动生成代码规则
前言 大家都清楚mybatis-generate-core 这个工程提供了获取表信息到生成model.dao.xml这三层代码的一个实现,但是这往往有一个痛点,比如需求来了,某个表需要增加字段,肯定需 ...
- MyBatis自动生成代码示例
在项目中使用到mybatis时,都会选择自动生成实体类,Mapper,SqlMap这三个东东. 手头上在用的又不方便,找了下网上,其实有很多文章,但有些引用外部文件时不成功,也不方便,所以重新整理了下 ...
- mybatis自动生成代码工具(逆向工程)
MyBatis自动生成实体类(逆向工程) MyBatis属于一种半自动的ORM框架,它需要我们自己编写sql语句和映射文件,但是编写映射文件和sql语句很容易出错,所以mybatis官方提供了Gene ...
- mybatis自动生成代码
使用maven集成mybatis-generator插件生成Mybatis的实体类,DAO接口和Map映射文件 本例中,使用的是mysql数据库 前提:表已经建好 mybatis框架的jar包,数据 ...
- Mybatis自动生成代码,MyBatis Generator
这还是在学校里跟老师学到的办法,然后随便在csdn下载一个并调试到可以用的状态. 基本由这几个文件组成,一个mysql连接的jar包.一个用于自动生成的配置文件,一个自动生成的jar包,运行jar包语 ...
随机推荐
- java电子书chm全套下载
链接:http://pan.baidu.com/s/1qWmMlYk 密码:us3x 版权声明:本文为博主原创文章,未经博主允许不得转载.
- Hive与Hbase结合使用
hive的启动需要使用到zookeeper, 所以, 要么自己搭建zookeeper, 要么跟其它东西一起使用, 我这里做的是跟hbase一起使用的zookeeper, 因为hbase自带zookee ...
- windows 服务器安装python及其基本库
步骤如下: 一.安装python软件: 1.进入windows服务器,从网址下载 python-3.5.4-amd64软件 到桌面: 2.在软件点右键,再“”以管理员身份运行“”,输入管理员密码: 3 ...
- angular使用base64的encode和decode
var app = angular.module("encodeDecode", []); app.controller("encodeDecodeCtrl", ...
- [转]简短介绍 C# 6 的新特性
原文地址:http://www.oschina.net/translate/briefly-exploring-csharp-new-features 几周前我在不同的地方读到了有关C#6的一些新特性 ...
- Entity Framework 分页处理
在SQL中进行分页,网上已经有很多例子了,在这里我使用Linq to SQL让C#来生成分页代码,首先创建分页的扩展方法: public static class Extensions { /// & ...
- React 从入门到进阶之路(三)
之前的文章我们介绍了 React 创建组件.JSX 语法.绑定数据和绑定对象.接下来我们将介绍 React 绑定属性( 绑定class 绑定style).引入图片 循环数组渲染数据. 上一篇中我们 ...
- MCP|WJ|Identification of candidate plasma protein biomarkers for cervical cancer using the multiplex proximity extension assay(利用多重邻位延伸分析技术进行宫颈癌血浆蛋白候选生物标记物的鉴定研究)
文献名:Identification of candidate plasma protein biomarkers for cervical cancer using the multiplex pr ...
- unique within an element
从tomcat 6 升到 tomcat-7.0.12 jsp页面报: org.apache.jasper.JasperException: /XXX/XXX.jsp(59,55) Attribute ...
- Nacos-spring-samples解析
小白们在看这个用例的时候得注意,这个东东不知道他是为了让大家能够快速体验还是怎么的, 反正我一开始没整明白,有点想当然的去理解了: 我一直以为这个Nacos-spring-samples只是一个简单的 ...