赞
踩
- <?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>
-
-
-
- <!-- targetRuntime="MyBatis3Simple":生成简单版的CRUD MyBatis3:豪华版 -->
-
- <context id="mybatis" targetRuntime="MyBatis3">
-
- <!-- jdbcConnection:指定如何连接到目标数据库 -->
-
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
-
- connectionURL="jdbc:mysql://localhost:3306/mybatis?allowMultiQueries=true"
-
- userId="root" password="123456">
-
- </jdbcConnection>
-
-
-
- <!-- -->
-
- <javaTypeResolver>
-
- <property name="forceBigDecimals" value="false" />
-
- </javaTypeResolver>
-
-
-
- <!-- javaModelGenerator:指定javaBean的生成策略 targetPackage="test.model":目标包名
-
- targetProject="\MBGTestProject\src":目标工程 -->
-
- <javaModelGenerator targetPackage="com.mybatis.bean"
-
- targetProject=".\src\main\java">
-
- <property name="enableSubPackages" value="true" />
-
- <property name="trimStrings" value="true" />
-
- </javaModelGenerator>
-
-
-
- <!-- sqlMapGenerator:sql映射生成策略: -->
-
- <sqlMapGenerator targetPackage="com.mybatis.dao"
-
- targetProject=".\src\main\resources">
-
- <property name="enableSubPackages" value="true" />
-
- </sqlMapGenerator>
-
-
-
- <!-- javaClientGenerator:指定mapper接口所在的位置 -->
-
- <javaClientGenerator type="XMLMAPPER"
-
- targetPackage="com.mybatis.dao" targetProject=".\src\main\java">
-
- <property name="enableSubPackages" value="true" />
-
- </javaClientGenerator>
-
-
-
- <!-- 指定要逆向分析哪些表:根据表要创建javaBean -->
-
- <table tableName="tbl_dept" domainObjectName="Department"
-
- enableCountByExample="false" enableDeleteByExample="false"
-
- enableSelectByExample="false" enableUpdateByExample="false"></table>
-
- <table tableName="tbl_employee" domainObjectName="Employee"
-
- enableCountByExample="false" enableDeleteByExample="false"
-
- enableSelectByExample="false" enableUpdateByExample="false"></table>
-
- </context>
-
- </generatorConfiguration>

1 添加jar包支持
mysql-connector-java-xxxx-bin.jar,mybatis-generator-core-xxx.jar
2 生成mybatis支持代码
- @Test
-
- public void testMbg() 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);
-
- }

1 添加maven环境需要插件支持
- <plugin>
-
- <groupId>org.mybatis.generator</groupId>
-
- <artifactId>mybatis-generator-maven-plugin</artifactId>
-
- <version>1.3.7</version>
-
- <dependencies>
-
- <dependency>
-
- <groupId>mysql</groupId>
-
- <artifactId>mysql-connector-java</artifactId>
-
- <version>5.1.41</version>
-
- </dependency>
-
- </dependencies>
-
- </plugin>

2 配置maven运行指令,并执行
先配置mybatis generator build,然后执行。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。