IntelliJ-IDEA中mybatis三剑客 一、mybatis-generator的使用 二、mybatis-plugin的使用
作用:根据数据库自动生成pojo、dao和xml文件。
1、引入mybatis-generator
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> <!--允许移动生成的文件--> <verbose>true</verbose> <!--允许覆盖生成的文件--> <overwrite>true</overwrite> </configuration> </plugin> </plugins> </build>
2、引入generatorConfig.xml
新建方法:在resources处右击选择New——>mybatis-generator-config
<?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包的位置--> <classPathEntry location="${db.driverLocation}"/> <context > <!-- 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"> <!-- 是否允许子包,即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"> <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"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- tableName对应数据库表 --> <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" />
<!-- sub_images是图片字段 --> <columnOverride column="sub_images" jdbcType="VARCHAR" /> </table> <table tableName="mmall_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> </context> </generatorConfiguration>
3、上面还需要引入datasource.properties
db.driverLocation=/Users/yujie/Workspaces/IdeaProjects/mmall_learing/lib/mysql-connector-java-5.1.6-bin.jar db.driverClassName=com.mysql.jdbc.Driver db.url=jdbc:mysql://127.0.0.1:3306/mmall?charcterEncoding=utf-8 db.username=root db.password=111111 db.initialSize = 20 db.maxActive = 50 db.maxIdle = 20 db.minIdle = 10 db.maxWait = 10 db.defaultAutoCommit = true db.minEvictableIdleTimeMillis = 3600000
添加完后,在Maven Projects的Plugins中会多出一个mybatis-generator,如图:
双击mybaitis-generator:generate,执行生成代码操作,然后查看对应包中都有相应的代码生成。
二、mybatis-plugin的使用
这是一个能够追踪dao 接口和mapper文件里xml的一个插件
1、安装插件
相关推荐
- excel提取文本格式时分秒中数字的方法并计算成秒的公式 display函数怎么使用_【Excel函数使用】时分秒时间怎么转换成秒?(一) 函数怎么使用 vue_【Excel函数使用】时分秒时间怎么转换成秒?(二)
- python 函数 一 数学定义的函数与python中的函数 二 为何使用函数 三 函数和过程 四 函数参数 五 局部变量和全局变量 六 前向引用之'函数即变量' 七 嵌套函数和作用域 八 递归调用 九 匿名函数 十 函数式编程 十一 内置函数
- sql 真的很不安全啊 一、检测注入点是否可用 二、暴库 三、web当前使用的数据库 四、web数据库使用账户 五、列出sqlserver所有用户 六、数据库账户与密码 七、列出数据库中的表 八、列出表中字段 九、暴字段内容 十、验证结果
- I/O流任务 一、完成以下链接[https://www.cnblogs.com/zhrb/p/6834084.html]中的任务3、4、5。 二、缓冲流(请自己设计实验进行测试)。尝试使用junit进行测试。 三、尝试结合DAO模式与本章所学内容,为购物车系统设计数据存储相关的StudentDao接口及其相关实现类。
- MyBatis 中 @Param 注解的四种使用场景,最后一种经常被人忽略! 前言 第一种:方法有多个参数,需要 @Param 注解 第二种:方法参数要取别名,需要 @Param 注解 第三种:XML 中的 SQL 使用了 $ ,那么参数中也需要 @Param 注解 第四种,那就是动态 SQL ,如果在动态 SQL 中使用了参数作为变量,那么也需要 @Param 注解,即使你只有一个参数。
- 这 8 种Synchronized 的用法,真是绝了! 简介 八种使用场景: 场景一:两个线程同时访问同一个对象的同步方法 场景二:两个线程同时访问两个对象的同步方法 场景三:两个线程同时访问(一个或两个)对象的静态同步方法 场景四:两个线程分别同时访问(一个或两个)对象的同步方法和非同步方法 场景五:两个线程访问同一个对象中的同步方法,同步方法又调用一个非同步方法 场景六:两个线程同时访问同一个对象的不同的同步方法 场景七:两个线程分别同时访问静态synchronized和非静态synchronized方法 场景八:同步方法抛出异常后,JVM会自动释放锁的情况 总结
- [iOS]关于视频方向的若干问题 一、MOV/MP4视频文件中的Rotation元数据 二、常见视频播放器对方向的识别 三、MPMoviePlayerViewController控制视频方向 四、HTML5控制视频方向 五、使用ffmpeg写入Rotation元数据 六、获取视频方向(角度) 七、按正确方向对视频进行截图 八、实时视频的方向处理 九、参考资料:
- sql server中使用链接服务器访问oracle数据库 一、 安装配置oracle客户端 二、 Sql server中新建指向orcacle的链接服务器 三、 在sql server中通过链接服务器访问orcale
- python基础之函数 一 数学定义的函数与python中的函数 二 为何使用函数 三 函数和过程 四 函数参数 五 局部变量和全局变量 六 前向引用之'函数即变量' 七 嵌套函数和作用域 八 递归
- Java多线程中的wait/notify通信模式 前言 一、什么是Java线程的等待/通知模式 二、代码举例 三、等待/通知模式的应用 四、wait()、notify()、notifyAll()使用前需要加锁的原因----防止线程即饥饿
- maven搭建ssm框架问题总结
- Advertising.csv