Mybatis自动生成java所需模型

来源:互联网 发布:网络销售是什么意思 编辑:程序博客网 时间:2024/06/14 06:09

生成时所需的xml文件(例子为postgresql)

<?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="D:\generator\postgresql-9.2-1003-jdbc4.jar" />        <context id="tts2">                <jdbcConnection driverClass="org.postgresql.Driver"                        connectionURL="jdbc:postgresql://localhost:5432/reporter_web"                        userId="postgres" password="root">                </jdbcConnection>          <!-- 生成模型的包名和位置 -->          <javaModelGenerator targetPackage="cn.ssms.model" targetProject="D:\generator\src">              <property name="enableSubPackages" value="true" />              <property name="trimStrings" value="true" />          </javaModelGenerator>          <!-- 生成的映射文件包名和位置 -->          <sqlMapGenerator targetPackage="cn.ssms.mapping" targetProject="D:\generator\src">              <property name="enableSubPackages" value="true" />          </sqlMapGenerator>          <!-- 生成DAO的包名和位置 -->          <javaClientGenerator type="XMLMAPPER" targetPackage="cn.ssms.dao" targetProject="D:\generator\src">              <property name="enableSubPackages" value="true" />          </javaClientGenerator>          <!--准备生成的数据表,以下为三张表-->         <table schema="public" tableName="clinical_c" domainObjectName="ClinicalC"></table>         <table schema="public" tableName="clinical_e" domainObjectName="ClinicalE"></table>         <table schema="public" tableName="clinical_ec" domainObjectName="ClinicalEc"></table>        </context></generatorConfiguration>

执行命令

在xml所放位置,打开cmd窗口,输入 java -jar mybatis-generator-core-1.3.2.jar -configfile mybaits.xml -overwrite

其它数据库

  <!-- 数据库链接URL、用户名、密码 -->       <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/demo?characterEncoding=utf8" userId="root" password="root">        <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="root" password="root">      </jdbcConnection>  
0 0
原创粉丝点击