2019独角兽企业重金招聘Python工程师标准>>>

一、非maven的方式:

1、首先使用eclipse新建一个java项目

2、然后添加mybatis-generator的jar包和oracle的驱动包,我这分别使用mybatis-generator-core-1.3.5.jar和ojdbc6-11.2.0.1.0.jar ,两个jar分别去官网下载即可,注意oracle的驱动包去官网下载的教程参见(> https://my.oschina.net/Sheamus/blog/1563614)

3、编写mybatis-generator的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration><!--数据库驱动--><classPathEntry    location="ojdbc6-11.2.0.1.0.jar"/><context id="DB2Tables"    targetRuntime="MyBatis3"><commentGenerator><property name="suppressDate" value="true"/><property name="suppressAllComments" value="true"/></commentGenerator><!--数据库链接地址账号密码--><jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@10.31.2.153:1521:orcl" userId="alarms" password="alarms"></jdbcConnection><javaTypeResolver><property name="forceBigDecimals" value="false"/></javaTypeResolver><!--生成Model类存放位置--><javaModelGenerator targetPackage="com.boco.model" targetProject="src"><property name="enableSubPackages" value="true"/><property name="trimStrings" value="true"/></javaModelGenerator><!--生成映射文件存放位置--><sqlMapGenerator targetPackage="com.boco.mapping" targetProject="src"><property name="enableSubPackages" value="true"/></sqlMapGenerator><!--生成Dao类存放位置--><javaClientGenerator type="XMLMAPPER" targetPackage="com.boco.dao" targetProject="src"><property name="enableSubPackages" value="true"/></javaClientGenerator><!--生成对应表及类名--><table tableName="DM_ALARM_TB" domainObjectName="Alarm" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_CHECKED_TABLES_TB" domainObjectName="CheckedTables" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_NORM_RULE_TB" domainObjectName="NormRule" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_NORM_TB" domainObjectName="Norm" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_RULE_ALARM_TB" domainObjectName="RuleAlarm" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_TASK_INFO_TB" domainObjectName="TaskInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_UNIFIED_ALARM_TB" domainObjectName="UnifiedAlarm" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table></context>
</generatorConfiguration>

上面的配置文件都有注解,按照上面的配置就可以了。

4、最后配置完成之后到项目的目录使用命令生成代码:

java -jar mybatis-generator-core-1.3.5.jar -configfile generatorConfig.xml -overwrite

估计这个过程要等一下,完成之后刷新一下项目就可以看到生成的代码 。

二、使用maven的方式生成代码:

1、创建一个maven项目

注意:eclipse创建maven项目可能要修改一下builder path里面的jdk版本,这样才会生成相应的maven项目目录,所以新建完成之后修改一下就可以了。 我这里的JDK是1.8,所以修改一下。

2、配置pom.xml文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.boco.generator</groupId><artifactId>generatorMaven</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>generatorMaven</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>11.2.0.1.0</version></dependency><dependency><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-core</artifactId><version>1.3.5</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency></dependencies><build><pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>1.8</source><target>1.8</target></configuration><version>3.3</version></plugin><plugin><groupId>org.mybatis.generator</groupId><artifactId>mybatis-generator-maven-plugin</artifactId><version>1.3.5</version><dependencies><dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>11.2.0.1.0</version></dependency></dependencies><configuration><!--配置文件的路径--><configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile> <overwrite>true</overwrite></configuration></plugin></plugins></pluginManagement></build></project>

3、在maven项目的resources目录添加配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfigurationPUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN""http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration><context id="test" targetRuntime="MyBatis3"><plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin>  <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin> <plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin> <commentGenerator><!-- 这个元素用来去除指定生成的注释中是否包含生成的日期 false:表示保护 --><!-- 如果生成日期,会造成即使修改一个字段,整个实体类所有属性都会发生变化,不利于版本控制,所以设置为true --><property name="suppressDate" value="true" /><!-- 是否去除自动生成的注释 true:是 : false:否 --><property name="suppressAllComments" value="false" /></commentGenerator><!--数据库链接URL,用户名、密码 --><jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver"connectionURL="jdbc:oracle:thin:@10.31.2.153:1521:orcl" userId="alarms" password="alarms"></jdbcConnection><javaTypeResolver><!-- This property is used to specify whether MyBatis Generator should force the use of java.math.BigDecimal for DECIMAL and NUMERIC fields, --><property name="forceBigDecimals" value="false" /></javaTypeResolver><!-- 生成模型的包名和位置 --><javaModelGenerator targetPackage="com.boco.pojo"targetProject="src/main/java"><property name="enableSubPackages" value="true" /><property name="trimStrings" value="true" /></javaModelGenerator><!-- 生成映射文件的包名和位置 --><sqlMapGenerator targetPackage="com.boco.mapping"targetProject="src/main/java"><property name="enableSubPackages" value="true" /></sqlMapGenerator><!-- 生成DAO的包名和位置 --><javaClientGenerator type="XMLMAPPER"targetPackage="com.boco.dao" implementationPackage="com.boco.dao.impl"  targetProject="src/main/java"><property name="enableSubPackages" value="true" /></javaClientGenerator><!-- 要生成哪些表 --><table tableName="DM_ALARM_TB" domainObjectName="Alarm" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_CHECKED_TABLES_TB" domainObjectName="CheckedTables" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_NORM_RULE_TB" domainObjectName="NormRule" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_NORM_TB" domainObjectName="Norm" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_RULE_ALARM_TB" domainObjectName="RuleAlarm" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_TASK_INFO_TB" domainObjectName="TaskInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table><table tableName="DM_UNIFIED_ALARM_TB" domainObjectName="UnifiedAlarm" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table></context>
</generatorConfiguration>

4、执行maven命令

命令:

mybatis-generator:generate

5、刷新项目就可以在src/main/java目录下看到生成的代码。

转载于:https://my.oschina.net/Sheamus/blog/1563684

mybatis oracle 使用mybatis-generator生成bean、mapper、dao相关推荐

  1. 已解决:springboot 用mybatis-generator自动生成bean和dao

    1.在pom.xml里添加maven插件: <plugin> <groupId>org.mybatis.generator</groupId> <artifa ...

  2. mybatis oracle trim,Mybatis trim标签

    trim代替where/set标签 trim是更灵活用来去处多余关键字的标签,它可以用来实现where和set的效果. SELECT * FROM user u u.username LIKE CON ...

  3. mybatis逆向工程用idea通过pom插件generator生成代码指令(mysql,oracle,sqlserver)

    一. F:/ideaProject/springboot-mybatis-demo mybatis-generator:generate -e 环境搭建: pom文件: <?xml versio ...

  4. 使用mybatis generator 生成annotation形式的mapper

    最近使用mybatisgenerator时,希望生成annotation的mapper,在网上基本桑没有相关配置,记录,做以下记录: [html] view plain copyprint? < ...

  5. Mybatis 在 IDEA 中使用 generator 逆向工程生成 pojo,mapper

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 使用mybatis可以逆向生成pojo和mapper文件有很多种方式,我以前用的是mybtais自带 ...

  6. mybatis oracle生成注释,MyBatis Generator生成Oracle数据库对应实体类时无法获取注释问题...

    最近在利用mybatis generator生成Oracle数据库对应的实体类时发现一个问题,特此记录下. 因为项目使用到了swagger2,所以想在生成实体类时通过表注释和字段注释生成对应的@Api ...

  7. Mybatis Generator生成工具使用

    一.创建数据库以及表t_user 二.引入依赖 <dependency><groupId>org.mybatis.generator</groupId><ar ...

  8. mybatis根据表逆向自动化生成代码(自动生成实体类、mapper文件、mapper.xml文件)

    若采用mybatis框架,数据库新建表,手动编写的话,需要编写大量的实体类.mapper文件.mapper.xml文件,都是一些重复且有规律的工作. 我们可以引用插件,然后做配置,自动生成这些文件,提 ...

  9. 你还在手写sql吗? MyBatis 逆向工程使用 使用逆向工程生成实体类,超级好用的生成实体类与mapper

    众所周知项目上的rbac在入门以后,熟悉掌握了以后,sql这些自己手动写起来是非常繁琐且无聊,那大家有没有想过用工具,只要创建表,然后使用工具告诉他一些实体类的名字跟其他信息让他自动帮我们生成这些sq ...

最新文章

  1. python vars()的用法
  2. linux 内核编译错误 Makefile:416: *** mixed implicit and normal rules: deprecated syntax
  3. opencv去除图片的高光
  4. java求数列的最大子段和_天下无双的公考必考题 数量关系: 最值问题②(构造数列)...
  5. httpClient学习的初步认识
  6. oracle求部门请假类别合计_【大话IT】求oracle sql 写法,找出同类的合计,所有的总计...
  7. php基础教程 第八步循环补充
  8. oracle创建简单包,Oracle创建程序包是什么?
  9. 脑残式网络编程入门(一):跟着动画来学TCP三次握手和四次挥手
  10. H3C PBR(策略路由)实验
  11. python装饰器打印函数执行时间_使用python装饰器计算函数运行时间的实例
  12. 武术擂台机器人所需传感器_华北工控:嵌入式计算机在AMR机器人中的应用
  13. 15个Rhino Grasshopper技巧【最新】
  14. 免费机器视觉视频教程halcon-百度网盘
  15. rf扫描枪_RF枪_RF手持扫描枪_RF手持机
  16. 宝塔面板无法连接FTP空间解决方法(超详细)
  17. 普通大一学生的自我反思
  18. Java jdt 编辑_java – 如何使用JDT以编程方式重命名方法
  19. 装饰公司如何做seo
  20. 【2020 ACM Fellow 华人学者】 陶宇飞 香港中文大学

热门文章

  1. 面向大数据的隐私保护
  2. Markov chain 整理
  3. java计算机毕业设计景区在线购票系统MyBatis+系统+LW文档+源码+调试部署
  4. 安装驱动程序(2)----安装过滤驱动
  5. GSEA富集分析:从概念理解到界面实操
  6. docker mysql 蜂巢_在网易蜂巢中创建和管理Docker容器的教程
  7. 最新历史版本 :H.265
  8. 字典数据结构-FST(Finite State Transducers)
  9. 【Flask框架】——第一个Flask项目
  10. 解决QQ会 应用程序正常初始化0xc0000005失败的办法