利用mybatis生成pojo,dao层,xml文件的相关配置
来源:互联网 发布:打豆豆小游戏优化版 编辑:程序博客网 时间:2024/06/08 12:51
我们在相关项目开发中经常要用到mybatis,它的一些插件例如mybatis generator 就是很好用的一个插件,下面简要介绍一下它的配置:
1:首先在pom文件中加入如下依赖:
<dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> <!-- <exclusions> <exclusion> <groupId>com.google.collections</groupId> <artifactId>google-collections</artifactId> </exclusion> </exclusions> --></dependency>
在配置该文件的时候一定要注意版本号,刚开始用的版本是1.3.4就会出现jar包冲突的问题,
2:接下来进行配置文件的设置:
<?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="db.properties"/> <!--数据库驱动的jar地址 --> <classPathEntry location="${classpath}"/> <context id="default" targetRuntime="MyBatis3"> <!-- 创建class时对注释进行控制 --> <commentGenerator> <!-- 是否生成注释时间戳 --> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="false"/> </commentGenerator> <jdbcConnection driverClass="${jdbc.driverClassName}" connectionURL="${jdbc.url}" userId="${jdbc.username}" password="${jdbc.password}"> </jdbcConnection> <!-- 类型转换 --> <javaTypeResolver > <!-- 是否使用bigDecimal,false可以自动转化以下类型long,Integer,short,etc --> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成实体类的地址 --> <javaModelGenerator targetPackage="com.listore.pojo" targetProject="./src/main/java"> <!-- 是否在当前路径下新加一层schema,eg:fase路径 --> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成map.xml文件 --> <sqlMapGenerator targetPackage="mappers" targetProject="./src/main/resources"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成DAO层文件的代码 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.listore.dao" targetProject="./src/main/java"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- <table schema="DB2ADMIN" tableName="ALLTYPES" domainObjectName="Customer" > <property name="useActualColumnNames" value="true"/> <generatedKey column="ID" sqlStatement="DB2" identity="true" /> <columnOverride column="DATE_FIELD" property="startDate" /> <ignoreColumn column="FRED" /> <columnOverride column="LONG_VARCHAR_FIELD" jdbcType="VARCHAR" /> </table> --> <!-- 用户表 --> <table tableName="listore_user" alias="user" domainObjectName="User" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"> </table> <!-- 购物车表 --> <table tableName="listore_cart" alias="cart" domainObjectName="Cart" enableUpdateByExample="false" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" ></table> <!-- 产品种类表 --> <table tableName="listore_category" alias="category" domainObjectName="Category" enableUpdateByExample="false" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"></table> <!-- 产品表 --> <table tableName="listore_product" alias="product" domainObjectName="Product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"><!--in database there is a text type,so in this configuration will
be VARCHAR in order to generator a String type in pojo class
--> <columnOverride column="detail" jdbcType="VARCHAR"/> <columnOverride column="sub_images" jdbcType="VARCHAR"/> </table> <!-- 订单表 --> <table tableName="listore_order" alias="order" domainObjectName="Order" enableCountByExample="false" enableDeleteByExample="false" enableUpdateByExample="false" enableSelectByExample="false"></table> <!-- 订单明细表 --> <table tableName="listore_order_item" alias="orderItem" domainObjectName="OrderItem" enableCountByExample="false" enableDeleteByExample="false" enableUpdateByExample="false" enableSelectByExample="false"></table> <!-- 收货地址表 --> <table tableName="listore_shipping" alias="shipping" domainObjectName="Shipping" enableCountByExample="false" enableDeleteByExample="false" enableUpdateByExample="false" enableSelectByExample="false"></table> <!-- 付款信息表 --> <table tableName="listore_pay_info" alias="payInfo" domainObjectName="PayInfo" enableCountByExample="false" enableDeleteByExample="false" enableUpdateByExample="false" enableSelectByExample="false"></table> </context></generatorConfiguration>
然后在idea的右侧Maven项目中选择下载好的mybatis-generotor.jar包双击就可以生成相应的文件了
阅读全文
0 0
- 利用mybatis生成pojo,dao层,xml文件的相关配置
- mybatis自动生成dao pojo xml文件工具(SQL server)
- 利用mybatis-generator生成dao-pojo-mapping
- Mybatis--使用mybatis generator插件映射数据库,自动生成pojo对象,dao接口,mapper.xml文件的方法
- doMoreDoBetter利用mybatis生成pojo、mapper接口、mapper XML文件
- 基于IdeaIDE的ssm整合框架的maven管理项目,利用映射自动生成dao层,pojo层,mappers层
- idea中mybatis-generator插件实现数据库表自动生成相关接口、pojo、和xml配置
- Mybatis逆向生成实体类,DAO层与mapper.xml文件
- 使用Mybatis-Generator自动生成Dao、model和mapper.xml相关文件
- 利用java工程配置文件生成数据表的增删改查dao层(xml)
- eclipse中安装mybatis generator插件自动生成dao、xml、pojo
- mybatis反向生成实体类、dao层以及映射文件
- 用mybatis-gennerator插件自动生成mybatis所需要的dao、bean、mapper xml文件
- mybatis 根据数据库表映射配置生成 模型 XML文件 Dao
- mybatis如何自动生成实体类,映射文件以及对应的dao层
- 利用Mybatis-Generator自动生成Dao、Model、Mapping等文件
- generator.xml文件自动生成mybatis的xml配置
- 使用Mybatis-Generator自动生成Dao、Model、Mapping相关文件
- SASS界面编译工具——Koala的使用
- 字符串数组
- 图中两个点之间的路线 -LintCode
- 注解Annotation
- ViewPager以及ViewFlipper的简单应用
- 利用mybatis生成pojo,dao层,xml文件的相关配置
- 非极大值抑制原理
- POJ2774(二分+哈希)
- 从小白开始入门python+tensorflow+cnn做人脸性别识别(一)
- hdu2774(后缀数组 最长公共子串)Long Long Message
- 关于递归算法的几个例子(C语言)
- PAT1074——Reversing Linked List
- spring mvc controller4中配置方式
- 【Java多线程】多线程案例:使用多线程向用户推送短信