• MyBatis Generator(SSM Maven项目)


    mbg.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="DB2Tables" targetRuntime="MyBatis3">
            <commentGenerator>
                <property name="suppressAllComments" value="true" />
            </commentGenerator>
            <!--配置数据库连接-->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://localhost:3306/ssm_crud?useSSL=true"
                            userId="root"
                            password="123456">
            </jdbcConnection>
    
    
            <javaTypeResolver >
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
    
            <!-- 指定javaBean生成的位置-->
            <javaModelGenerator targetPackage="xyz.sun.crud.bean"
                                targetProject=".srcmainjava">
                <property name="enableSubPackages" value="true" />
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
    
            <!--指定sql文件生成的位置-->
            <sqlMapGenerator targetPackage="mapper"
                             targetProject=".srcmain
    esources">
                <property name="enableSubPackages" value="true" />
            </sqlMapGenerator>
    
    
            <!-- 指定dao接口生成的位置  mapper接口-->
            <javaClientGenerator type="XMLMAPPER" targetPackage="xyz.sun.crud.dao"
                                 targetProject=".srcmainjava">
                <property name="enableSubPackages" value="true" />
            </javaClientGenerator>
    
            <!-- table 指定每个表的生成策略-->
            <table tableName="tbl_emp" domainObjectName="Employee"></table>
            <table tableName="tbl_dept" domainObjectName="Department"></table>
    
        </context>
    </generatorConfiguration>

    MBGTest

    package xyz.sun.crud.test;
    
    import org.mybatis.generator.api.MyBatisGenerator;
    import org.mybatis.generator.config.Configuration;
    import org.mybatis.generator.config.xml.ConfigurationParser;
    import org.mybatis.generator.internal.DefaultShellCallback;
    
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    
    public class MBGTest {
        public static void main(String[] args) throws Exception {
            List<String> warnings = new ArrayList<String>();
            boolean overwrite = true;
            File configFile = new File("mbg.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);
        }
    }
  • 相关阅读:
    VS 2015 GIT操作使用说明
    态度以及业余付出决定程序生涯
    Magicodes.WeiChat——使用OAuth 2.0获取微信用户信息
    Magicodes.WeiChat——ASP.NET Scaffolding生成增删改查、分页、搜索、删除确认、批量操作、批量删除等业务代码
    Magicodes.WeiChat——利用纷纭打造云日志频道
    Magicodes.WeiChat——自定义knockoutjs template、component实现微信自定义菜单
    产品管理之敏捷之路(一)——携手同行,走自己的敏捷之路
    Magicodes.NET框架之路——V0.0.0.5 Beta版发布
    Spring mvc中@RequestMapping 6个基本用法小结
    spring.net aop 讲解
  • 原文地址:https://www.cnblogs.com/mzdljgz/p/11152686.html
Copyright © 2020-2023  润新知