Mybatis(1)——Mybatis Generator自动生成代码
下载地址:https://github.com/mybatis/mybatis-3/releases?after=mybatis-3.2.8
二、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>
<!-- 数据库驱动--> <classPathEntry location="ojdbc6-1.0.0.jar"/> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--数据库链接URL,用户名、密码 --> <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@10.11.11.8:1521/XHY" userId="xhy" password="xhy"> </jdbcConnection><!--数据库中所有number类型的字段,生成POJO时都映射为BigDecimal类型--> <javaTypeResolver> <property name="forceBigDecimals" value="true"/> </javaTypeResolver> <!-- 生成模型的包名和位置--> <javaModelGenerator targetPackage="com.cah.xhy.model" targetProject="src"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成映射文件的包名和位置--> <sqlMapGenerator targetPackage="MybatisMapper" targetProject="src"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成DAO的包名和位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.cah.xhy.dao" targetProject="src"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--> <table tableName="ws_ips_purchaseplan" domainObjectName="PurchasePlan" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="ws_ips_purchaseplan_idoc" domainObjectName="Invoice" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="ws_ips_purchaseplan_import" domainObjectName="InvoiceDetail" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="ws_ips_packing_list" domainObjectName="Package" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table></context>
</generatorConfiguration>
四、生成代码Oracle的number类型字段
1、生成代码时,Oracle字段类型如果是number类型(后面不带精度),则生成的实体类中,该字段是Short类型的
2、如果generatorConfig.xml中配置了:
<javaTypeResolver> <property name="forceBigDecimals" value="true"/> </javaTypeResolver>
则生成的实体类中,所有number类型的字段(不管有没有设置精度),都是BigDecimal类型
3、否则会根据精度不同生成不同的类型:
number长度 | Java类型 |
1~4 | Short |
5~9 | Integer |
10~18 | Long |
18+ | BigDecimal |
Mybatis(1)——Mybatis Generator自动生成代码相关推荐
- SpringBoot如何自动生成实体类和Dao层以及映射文件(mybatis generator 自动生成代码)
一.首先添加自动生成代码插件 <!-- mybatis generator 自动生成代码插件 生成时解除注释 --><plugin><groupId>org.myb ...
- SpringBoot入门篇--整合mybatis+generator自动生成代码+druid连接池+PageHelper分页插件
我们这一一篇博客讲的是如何整合Springboot和Mybatis框架,然后使用generator自动生成mapper,pojo等文件.然后再使用阿里巴巴提供的开源连接池druid,这个连接池的好处我 ...
- 用mybatis的generator自动生成代码--坑我都走了一遍,后面的同学别踩了
先说什么是mybatis-generator? mybatis-geneator是一款mybatis自动代码生成工具,可以通过配置,快速生成mapper和xml文件. 步骤一:在pom文件中添加插件配 ...
- 使用Mybatis Generator自动生成代码
MyBatis Generator(MBG)是MyBatis MyBatis 和iBATIS的代码生成器. 它将为所有版本的MyBatis以及版本2.2.0之后的iBATIS版本生成代码. 它将内省数 ...
- mybatis generator 自动生成代码(带注释的实体类)
使用前提: 当你开发的java 项目或新模块的数据库有N张表操作时,这时要自己写实体类.dao.SqlMapper.xml等文件,如果有多个表,就是造成时间浪费降低开发效率,所以建议使用mybatis ...
- Eclipse使用mybatis generator自动生成代码
一.写在前面 Mybatis属于半自动ORM,在使用这个框架中,工作量最大的就是书写Mapping的映射文件,由于手动书写很容易出错,我们可以利用Mybatis-Generator来帮我们自动生成文件 ...
- maven mybatis generator自动生成代码
利用maven插件生成mybatis的 mapper dao entity 大大减少了工作量. 我的环境 Eclipse Java EE IDE for Web Developers. Version ...
- SpringBoot 系列教程(五十一):SpringBoot整合Mybatis Plus代码生成器,自动生成代码
MyBatis-Plus 为简化开发而生 快速开始 → 一.简介 MyBatis-Plus (简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发. ...
- 关于MybatisPlus使用Generator自动生成代码的实现(包含创建时间和更新时间的自动填充)
基于springboot的基础上添加以下依赖 <dependency><groupId>com.baomidou</groupId><artifactId&g ...
最新文章
- 【iOS数据持久化】偏好设置(UserDefaults)
- python querystring encode_Java UriUtils.encodeQueryParam方法代碼示例
- Duilib教程-自动布局2
- IE6的Bug: 绝对定位遇到浮动后消失
- azure云数据库_Azure SQL数据库地理复制
- Arcgis Javascript API 开发笔记
- java horizontalbarchart_DOC-03-36 柱状图(Bar Chart)
- java 门票订购系统_基于jsp的景区门票订购系统-JavaEE实现景区门票订购系统 - java项目源码...
- 中英文数字混合的复合格式处理
- 实验吧 WEB 猫抓老鼠
- java水平翻转矩阵_Java实现 LeetCode 519 随机翻转矩阵
- 基于Python技术的营养信息管理系统
- nvidia驱动版本查询
- android 图片凸出
- C语言求素数案例讲解
- 保边滤波之引导滤波与领域转换滤波
- Navicat Premium闪退,求助
- OceanBase 架构初探
- 问题十三:按照气象划分法,通常以阳历3~5月为春季,6~8月为夏季,9~11月为秋季,12月~来年2月为冬季。使用switch结构编写函数根据月份输出对应的季节。
- 百胜软件 武汉php,熹茗茶业百胜软件达成合作,共促茶业信息化发展进程