zoukankan      html  css  js  c++  java
  • Mybatis 如何自动生成bean dao xml 配置文件 generatorconfig.xml (mysql)

    1/自动生成的jar包:mybatis-generator-core-1.3.2.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> 
    <classPathEntry location="lib/mysql-connector-5.1.8.jar" />
    <context id="MySqlTables" targetRuntime="MyBatis3">
    <!--配置数据库链接-->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" 
    connectionURL="jdbc:mysql://localhost:3306/abcProject?characterEncoding=utf8" userId="root"
    password="11112222"> 
    </jdbcConnection>
    <javaTypeResolver> 
    <property name="forceBigDecimals" value="false" /> 
    </javaTypeResolver> 
           

    <!--配置实体bean-->
    <javaModelGenerator targetPackage="xmlParer" 
    targetProject="D: estxmlParer"> 
    <property name="enableSubPackages" value="true" /> 
    <property name="trimStrings" value="true" /> 
    </javaModelGenerator> 
    <!--配置实体map接口(dao)-->   
    <sqlMapGenerator targetPackage="xmlParer" 
    targetProject="D: estxmlParer"> 
    <property name="enableSubPackages" value="true" /> 
    </sqlMapGenerator> 
        
    <!--配置实体bean的sql.xml-->   
    <javaClientGenerator type="XMLMAPPER" 
    targetPackage="xmlParer"
    targetProject="D: estxmlParer">
     <property name="enableSubPackages" value="true" /> 
    </javaClientGenerator>
    <!--配置实体-->  
     <table tableName="abc_agency" domainObjectName="Agency">
     
    </table> 
    </context> 
    </generatorConfiguration>


    3.1/  执行命令
    java -jar mybatis-generator-core-1.3.0.jar -configfile  D: estgeneratorconfig.xml -overwrite 
    这样基本就ok了。


    3.2 Main方法执行

     List<String> warnings = new ArrayList<String>();
      boolean overwrite = true;
      File configFile = new File("src/generatorConfig.xml");
      ConfigurationParser cp = new ConfigurationParser(warnings);
      Configuration config;
      try {
       config = cp.parseConfiguration(configFile);
       DefaultShellCallback callback = new DefaultShellCallback(overwrite);
       MyBatisGenerator myBatisGenerator;
       try {
        myBatisGenerator = new MyBatisGenerator(config, callback,
          warnings);
        myBatisGenerator.generate(null);
       } catch (Exception e) {
        e.printStackTrace();
       }

  • 相关阅读:
    剑指offer 顺时针打印矩阵
    剑指offer队列中的最大值
    固定顶部指定div不滑动
    调整圆环统计图格式
    补插一个MUI中UI组件示例地址
    统计图左右滑动
    mui集成百度ECharts的统计图表以及清空释放图表
    页面ajax自带的访问后台时,正在加载中
    js弹出div层内容(按回退键关闭div层及遮罩)
    地图经纬度定位不准
  • 原文地址:https://www.cnblogs.com/huapox/p/3516398.html
Copyright © 2011-2022 走看看