mybatis的三大剑客

编程入门 行业动态 更新时间:2024-10-06 10:32:25

mybatis的<a href=https://www.elefans.com/category/jswz/34/1767861.html style=三大剑客"/>

mybatis的三大剑客

哪三大我就不说了,就说一说genertaor生成代码。
1、datasource.properties

db.driverLocation=/Users/Administrator/workspace/yhMall/tools/mysql-connector-java-5.1.6-bin.jardb.driverClassName=com.mysql.jdbc.Driver#db.url=jdbc:mysql://192.1.1.1:3306/mmall?characterEncoding=utf-8
db.url=jdbc:mysql://127.0.0.1/mmshop?characterEncoding=utf-8
db.username=root
db.password=934247746db.initialSize = 20
db.maxActive = 50
db.maxIdle = 20
db.minIdle = 10
db.maxWait = 10
db.defaultAutoCommit = true
db.minEvictableIdleTimeMillis = 3600000

2、generatorConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfigurationPUBLIC "-//mybatis//DTD MyBatis Generator Configuration 1.0//EN"".dtd"><generatorConfiguration><!--导入属性配置--><properties resource="datasource.properties"></properties><!--指定特定数据库的jdbc驱动jar包的位置--><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.yanhui.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.yanhui.dao" targetProject="./src/main/java"><!-- enableSubPackages:是否让schema作为包的后缀 --><property name="enableSubPackages" value="false" /></javaClientGenerator><table tableName="mmshop_shipping" domainObjectName="Shipping" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="mmshop_cart" domainObjectName="Cart" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="mmshop_cart_item" domainObjectName="CartItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="mmshop_category" domainObjectName="Category" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="mmshop_order" domainObjectName="Order" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="mmshop_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="mmshop_pay_info" domainObjectName="PayInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="mmshop_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="mmshop_user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><!-- geelynote mybatis插件的搭建 --></context>
</generatorConfiguration>

3、run as

mybatis-generator:generate

4、mapper层 时间改为now()

5、eclipse安装mybatis-plugins
安装地址:
实现效果:快速定位到mybatis的xml (mapper)文件

6、还有一个剑客就是mybatis分页,就不说了。

7、公欲善其事,必先利其器。
FEHelper:显示json格式的
restlet_client:测试url返回有没有错

更多推荐

mybatis的三大剑客

本文发布于:2024-02-14 11:42:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1763193.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:三大   剑客   mybatis

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!