MyBatis - 三剑客之 Mybatis-Generator

简介: MyBatis - 三剑客之 Mybatis-Generator

前言

自动化生成数据库交互代码:DAO接口 & DAO接口实现类(mapper.xml)& 实体类。

快速入门

<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEgeneratorConfigurationPUBLIC"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><generatorConfiguration><!--导入属性配置--><propertiesresource="datasource.properties"></properties><!--指定特定数据库的jdbc驱动jar包的位置--><classPathEntrylocation="${db.driverLocation}"/><contextid="default"targetRuntime="MyBatis3"><!--optional,旨在创建class时,对注释进行控制--><commentGenerator><propertyname="suppressDate"value="true"/><propertyname="suppressAllComments"value="true"/></commentGenerator><!--jdbc的数据库连接--><jdbcConnectiondriverClass="${db.driverClassName}"connectionURL="${db.url}"userId="${db.username}"password="${db.password}"></jdbcConnection><!--非必需,类型处理器,在数据库类型和java类型之间的转换控制--><javaTypeResolver><propertyname="forceBigDecimals"value="false"/></javaTypeResolver><!--Model模型生成器,用来生成含有主键key的类,记录类以及查询Example类targetPackage指定生成的model生成所在的包名targetProject指定在该项目下所在的路径--><!--<javaModelGeneratortargetPackage="com.mmall.pojo"targetProject=".\src\main\java">--><javaModelGeneratortargetPackage="com.mmall.pojo"targetProject="./src/main/java"><!--是否允许子包,即targetPackage.schemaName.tableName--><propertyname="enableSubPackages"value="false"/><!--是否对model添加构造函数--><propertyname="constructorBased"value="true"/><!--是否对类CHAR类型的列的数据进行trim操作--><propertyname="trimStrings"value="true"/><!--建立的Model对象是否不可改变即生成的Model对象不会有setter方法,只有构造方法--><propertyname="immutable"value="false"/></javaModelGenerator><!--mapper映射文件生成所在的目录为每一个数据库的表生成对应的SqlMap文件--><!--<sqlMapGeneratortargetPackage="mappers"targetProject=".\src\main\resources">--><sqlMapGeneratortargetPackage="mappers"targetProject="./src/main/resources"><propertyname="enableSubPackages"value="false"/></sqlMapGenerator><!--客户端代码,生成易于使用的针对Model对象和XML配置文件的代码type="ANNOTATEDMAPPER",生成JavaModel和基于注解的Mapper对象type="MIXEDMAPPER",生成基于注解的JavaModel和相应的Mapper对象type="XMLMAPPER",生成SQLMapXML文件和独立的Mapper接口--><!--targetPackage:mapper接口dao生成的位置--><!--<javaClientGeneratortype="XMLMAPPER"targetPackage="com.mmall.dao"targetProject=".\src\main\java">--><javaClientGeneratortype="XMLMAPPER"targetPackage="com.mmall.dao"targetProject="./src/main/java"><!--enableSubPackages:是否让schema作为包的后缀--><propertyname="enableSubPackages"value="false"/></javaClientGenerator><tabletableName="mmall_shipping"domainObjectName="Shipping"enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"></table><tabletableName="mmall_cart"domainObjectName="Cart"enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"></table><tabletableName="mmall_cart_item"domainObjectName="CartItem"enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"></table><tabletableName="mmall_category"domainObjectName="Category"enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"></table><tabletableName="mmall_order"domainObjectName="Order"enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"></table><tabletableName="mmall_order_item"domainObjectName="OrderItem"enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"></table><tabletableName="mmall_pay_info"domainObjectName="PayInfo"enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"></table><tabletableName="mmall_product"domainObjectName="Product"enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"><columnOverridecolumn="detail"jdbcType="VARCHAR"/><columnOverridecolumn="sub_images"jdbcType="VARCHAR"/></table><tabletableName="mmall_user"domainObjectName="User"enableCountByExample="false"enableUpdateByExample="false"enableDeleteByExample="false"enableSelectByExample="false"selectByExampleQueryId="false"></table><!--geelynotemybatis插件的搭建--></context></generatorConfiguration>

image.png

目录
相关文章
|
XML Java 数据库连接
Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(下)
Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(下)
243 0
Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(下)
|
Java 数据库连接 Maven
Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(上)
Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(上)
157 0
Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(上)
|
Java Apache Maven
mybatis-generator运行报错Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate (default-cli) on project testone: Exec
"C:Program FilesJavajdk-9.0.4binjava.exe" -Dmaven.multiModuleProjectDirectory=E:testone "-Dmaven.home=D:IDEAIntelliJ IDEA 2018.
16181 0
|
SQL XML Java
Mybatis-Generator_学习_01_mybatis-generator笔记
一.generatorConfig.xml DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.
1170 0
|
关系型数据库 Java 数据库连接
Mybatis-Generator_学习_02_使用Mapper专用的MyBatis Generator插件
源码见:https://github.com/shirayner/tk-mybatis-generator    一、要点     二、具体实现 1.项目结构   2.配置 pm.
1432 0
|
14天前
|
缓存 前端开发 Java
【Java面试题汇总】Spring,SpringBoot,SpringMVC,Mybatis,JavaWeb篇(2023版)
Soring Boot的起步依赖、启动流程、自动装配、常用的注解、Spring MVC的执行流程、对MVC的理解、RestFull风格、为什么service层要写接口、MyBatis的缓存机制、$和#有什么区别、resultType和resultMap区别、cookie和session的区别是什么?session的工作原理
【Java面试题汇总】Spring,SpringBoot,SpringMVC,Mybatis,JavaWeb篇(2023版)
|
1天前
|
SQL XML Java
springboot整合mybatis-plus及mybatis-plus分页插件的使用
这篇文章介绍了如何在Spring Boot项目中整合MyBatis-Plus及其分页插件,包括依赖引入、配置文件编写、SQL表创建、Mapper层、Service层、Controller层的创建,以及分页插件的使用和数据展示HTML页面的编写。
springboot整合mybatis-plus及mybatis-plus分页插件的使用
|
29天前
|
Java 数据库连接 测试技术
SpringBoot 3.3.2 + ShardingSphere 5.5 + Mybatis-plus:轻松搞定数据加解密,支持字段级!
【8月更文挑战第30天】在数据驱动的时代,数据的安全性显得尤为重要。特别是在涉及用户隐私或敏感信息的应用中,如何确保数据在存储和传输过程中的安全性成为了开发者必须面对的问题。今天,我们将围绕SpringBoot 3.3.2、ShardingSphere 5.5以及Mybatis-plus的组合,探讨如何轻松实现数据的字段级加解密,为数据安全保驾护航。
82 1