mybatis 三剑客 之 generator
简介
简单来说, 可以根据数据库生成一定的java代码。但是负载的逻辑还得自己实现。
就酱
参考连接
http://mybatis.org/generator/ 官网信息
https://www.imooc.com/article/306421 相关的配置信息
https://zhuanlan.zhihu.com/p/133269734 全部的三剑客
生成文件的目录
可以再generator里面进行配置。
maven
配置
pom.xml
<build>
<finalName>mmall</finalName>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!--如果不配置configurationFile,默认为 resources/generatorConfig.xml-->
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin>
</plugins>
</build>
TIPS
会读取 文件resources/generatorConfig.xml 进行加载。
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>
<!--导入属性配置-->
<properties resource="datasource.properties"></properties>
<!--指定特定数据库的jdbc驱动jar包的位置, db 配置再datasource.properties文件中进行了配置-->
<classPathEntry location="${db.driverLocation}"/>
<context id="default" targetRuntime="MyBatis3">
<!-- optional,旨在创建class时,对注释进行控制 -->
<commentGenerator>
<property name="suppressDate" value="true"/>
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--jdbc的数据库连接 -->
<jdbcConnection
driverClass="${db.driverClassName}"
connectionURL="${db.url}"
userId="${db.username}"
password="${db.password}">
</jdbcConnection>
<!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制-->
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
targetPackage 指定生成的model生成所在的包名
targetProject 指定在该项目下所在的路径
-->
<!--<javaModelGenerator targetPackage="com.mmall.pojo" targetProject=".\src\main\java">-->
<javaModelGenerator targetPackage="com.mmall.pojo" targetProject="./src/main/java">
<!-- 是否允许子包,即targetPackage.schemaName.tableName -->
<property name="enableSubPackages" value="false"/>
<!-- 是否对model添加 构造函数 -->
<property name="constructorBased" value="true"/>
<!-- 是否对类CHAR类型的列的数据进行trim操作 -->
<property name="trimStrings" value="true"/>
<!-- 建立的Model对象是否 不可改变 即生成的Model对象不会有 setter方法,只有构造方法 -->
<property name="immutable" value="false"/>
</javaModelGenerator>
<!--mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
<!--<sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources">-->
<sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources">
<property name="enableSubPackages" value="false"/>
</sqlMapGenerator>
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口
-->
<!-- targetPackage:mapper接口dao生成的位置 -->
<!--<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject=".\src\main\java">-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.mmall.dao" targetProject="./src/main/java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table tableName="mmall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_cart" domainObjectName="Cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_cart_item" domainObjectName="CartItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_order" domainObjectName="Order" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_pay_info" domainObjectName="PayInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="mmall_product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
<columnOverride column="detail" jdbcType="VARCHAR" />
<columnOverride column="sub_images" jdbcType="VARCHAR" />
</table>
<table tableName="mmall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<!-- geelynote mybatis插件的搭建 -->
</context>
</generatorConfiguration>
TIPS
再mapper文件里面最好, updatetime 时间设定为, now()函数, java代码就可以不用管,直接使用数据库函数。
mybatis 三剑客 之 generator的更多相关文章
- Mybatis—三剑客之generator使用方法
三剑客之generator主要用于自动生成POJO实体类 准备素材: mybatis-generator-core-1.3.2.jar mysql-connector-java-5.1.2 ...
- Intellij IDEA 2017集成MyBatis三剑客
MyBatis三剑客指的是:MyBatis-Generate.Mybatis Plus.MyBatis-PageHelper MyBatis-Generate 使用 Mybatis Generator ...
- mybatis 三剑客 generator配置 、mybatis plugin
generator配置 1.配置pom.xml 导入mysql驱动.mybatis.mybatis-generator的依赖 <dependency> <groupId>org ...
- Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解
生成器设计思路: 连接数据库 -> 获取表结构 -> 生成文件 1 下载与安装 官网文档入口 最方便的 maven 插件使用方式 贴至pom 文件 2 新建配置文件 填充配置信息(官网示例 ...
- springboot学习随笔(四):Springboot整合mybatis(含generator自动生成代码)
这章我们将通过springboot整合mybatis来操作数据库 以下内容分为两部分,一部分主要介绍generator自动生成代码,生成model.dao层接口.dao接口对应的sql配置文件 第一部 ...
- Mybatis三剑客之mybatis-generator配置
mybatis插件在这里: 然后把generatorConfig.xml文件放在resources下: <?xml version="1.0" encoding=" ...
- Mybatis三剑客介绍
1.MyBatis generator 利用mybatis-generator自动生成代码 下载地址: https://download.csdn.net/download/qq_36625806/ ...
- 【mybatis】mybaits generator 逆向工程的使用
mybatis逆向工程官方网站:http://www.mybatis.org/generator/quickstart.html 准备xml文件.如下generator.xml全部内容 <?xm ...
- mybatis代码生成(generator工具生成代码)
generator工具生成代码 下载地址 http://pan.baidu.com/s/1bY8C0I
- 【mmall】mybatis三剑客
mybatis-generator mybatis-plugin Mybatis Plugin插件安装破解及使用:http://blog.csdn.net/u011410529/article/det ...
随机推荐
- pytorch 实战教程之 SPP(SPPNet---Spatial Pyramid Pooling)空间金字塔池化网络代码实现 和 SPPF (Spatial Pyramid Pooling Fast)详解
原文作者:aircraft 原文链接:pytorch 实战教程之 SPP(SPPNet---Spatial Pyramid Pooling)空间金字塔池化网络代码实现 和 SPPF (Spatial ...
- springboot分页查询并行优化实践
--基于异步优化与 MyBatis-Plus 分页插件思想的实践 适用场景 数据量较大的单表分页查询 较复杂的多表关联查询,包含group by等无法进行count优化较耗时的分页查询 技术栈 核心框 ...
- TVM:使用自动调度优化算子
与基于模板的AutoTVM不同(会依赖手动模板定义搜索空间),自动调度器不需要任何模板.用户只需要编写计算声明,而不需要任何调度命令或模板.自动调度器可以自动生产一个大的搜索空间,并在空间中找到一个好 ...
- Django踩坑之django.core.exceptions.ImproperlyConfigured mysqlclient 1.3.13 or newer is required; you have 0.9.3.
安装Django3后不想折腾mysqlclient那堆库文件,直接装了pymysql替代mysqlclient,报错:django.core.exceptions.ImproperlyConfigur ...
- ISCC2025破阵夺旗赛三阶段Misc详解 By Alexander
ISCC2025破阵夺旗赛三阶段Misc详解 By Alexander 写在前面:十八天吃石终于结束了,第一次就让我见到了这个比赛有多么的构式,平台是构式的,睡一觉就1000解了,全是对flag的渴望 ...
- 数据类型转换(java)
默认转换(从小到大 /*联想式理解:从弱变强 因为代码的世界是正能量的,所以可以默许蜕变得原来越好哇*/) byte(1),short(2),char -> int(4) -> long( ...
- Longest Palindromic Substring-----LeetCode进阶路⑤
题目描述 Given a string s, find the longest palindromic substring in s. You may assume that the maximum ...
- Linux如何进入bios
如何通过Linux系统进入bios 我们都知道在系统没启动前用按键进入bios,但是如果在启动没启动之前按键失效(bios里面设置的原因). 如果能进入linux系统,那么可以执行 sudo syst ...
- Spring注解之@Autowired:装配构造函数和属性
在User类中创建一个构造函数,传入参数student: import org.springframework.beans.factory.annotation.Autowired; import o ...
- logback.xml配置分享
前言 个人习惯,仅供学习参考 功能 日志异步输出 日志每天自动归档一次 日志文件达到一定大小时,也会进行归档 归档时,进行zip压缩 归档的日志放在 yyyy-MM-dd 文件夹中 当归档的日志文件总 ...