myBatisGenerator
来源:互联网 发布:swf文件mac用什么打开 编辑:程序博客网 时间:2024/05/23 23:23
myBatis逆向工程:
由数据库的表生成java代码
3.添加一个java程序,加入对应代码。执行对应代码
由数据库的表生成java代码
利用xml配置文件和java程序生成:
1.在项目中引入mybatisGenerator相关jar包
mybatis-generator-core-1.3.2.jar
mybatis-generator-core-1.3.2-javadoc.jar
mybatis-generator-core-1.3.2-sources.jar
2.在项目一级目录下配置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><context id="testTables" targetRuntime="MyBatis3"><commentGenerator><!-- 是否去除自动生成的注释 true:是 : false:否 --><property name="suppressAllComments" value="true" /></commentGenerator><!--数据库连接的信息:驱动类、连接地址、用户名、密码 --><jdbcConnection driverClass="com.mysql.jdbc.Driver"connectionURL="jdbc:mysql://192.168.10.1:3306/company?useSSL=false" userId="root"password="Lxy402216351."></jdbcConnection><!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg" userId="yycg"password="yycg"></jdbcConnection> --><!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --><javaTypeResolver><property name="forceBigDecimals" value="false" /></javaTypeResolver><!-- targetProject:生成PO类的位置 --><javaModelGenerator targetPackage="com.hy.company.core.domain"targetProject=".\src\main\java"><!-- enableSubPackages:是否让schema作为包的后缀 --><property name="enableSubPackages" value="false" /><!-- 从数据库返回的值被清理前后的空格 --><property name="trimStrings" value="true" /></javaModelGenerator> <!-- targetProject:mapper映射文件生成的位置 --><sqlMapGenerator targetPackage="mappers" targetProject=".\src\main\resources"><!-- enableSubPackages:是否让schema作为包的后缀 --><property name="enableSubPackages" value="false" /></sqlMapGenerator><!-- targetPackage:mapper接口生成的位置 --><javaClientGenerator type="XMLMAPPER"targetPackage="com.hy.company.core.mapper" targetProject=".\src\main\java\"><!-- enableSubPackages:是否让schema作为包的后缀 --><property name="enableSubPackages" value="false" /></javaClientGenerator><!-- 指定数据库表 --><table tableName="t_user"></table><table tableName="userorder"></table><table tableName="order_detail"></table></context></generatorConfiguration>
3.添加一个java程序,加入对应代码。执行对应代码
package com.hy.company.core.domain;import java.io.File;import java.io.IOException;import java.util.ArrayList;import java.util.List;import org.mybatis.generator.api.MyBatisGenerator;import org.mybatis.generator.config.Configuration;import org.mybatis.generator.config.xml.ConfigurationParser;import org.mybatis.generator.exception.InvalidConfigurationException;import org.mybatis.generator.exception.XMLParserException;import org.mybatis.generator.internal.DefaultShellCallback;public class GeneratorSqlMap {public void generator() throws Exception{List<String> warnings = new ArrayList<String>(); boolean overwrite = true; File configFile = new File("generatorConfig.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(configFile); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(null);}public static void main(String[] args) throws Exception {new GeneratorSqlMap().generator();}}
配置执行完毕后,会生成数据库表对应的实体类,maper.xml文件,maper.java文件;
附带生成的Example类,加了许多东西,实际项目使用时可能会感到多余,这个问题具体使用时再研究。。。。。。
阅读全文
0 0
- myBatisGenerator
- MybatisGenerator的使用
- MybatisGenerator工具使用简介
- MybatisGenerator的自动生成
- MybatisGenerator的使用记录
- 搭建SpringBoot-MyBatis-MyBatisGenerator项目
- MBG(mybatisgenerator)自动生成工具
- Mybatis自动代码生成插件MybatisGenerator使用
- idea使用MybatisGenerator逆向生成DAO文件
- MyBatisGenerator生成文件自定义名字-MBG扩展
- MyBatisGenerator的自动生成代码之Eclipse
- MyBatisGenerator的自动生成代码之MyEclipse
- MyBatisGenerator的自动生成代码之MyEclipse
- MyBatisGenerator的自动生成代码之Eclipse
- MyBatisGenerator 自动生成java代码(反向工具)
- mybatisGenerator 代码自动生成报错 Result Maps collection already contains value for BaseResultMap
- eclipse使用MyBatisGenerator自动生成相关文件出错:project does not exist
- mybatisGenerator 代码自动生成报错 Result Maps collection already contains value for BaseResultMap
- windows系统下Python环境的搭建-(转)
- 基数排序
- Linux下安装飞秋——可以和windows通信
- Unity编辑器基础
- HiveMetaStore高可用性(HA)配置
- myBatisGenerator
- android项目从零开始 gradle 打包差别配置 区分
- java.lang.RuntimeException: setParameters failed
- Eventbus传值
- 欢迎使用CSDN-markdown编辑器
- 电信3G典型拨号脚本
- JavaScript、jQuery、AJAX、JSON 这四个之间的关系 神段子 通俗易懂
- webapi全局日志方法
- if-else