mybatis学习笔记(六)使用generator生成mybatis基础配置代码和目录结构
原文:http://blog.csdn.net/oh_mourinho/article/details/51463413
创建maven项目
- <span style="font-size:14px;"><project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.liyb.mybatis.stud</groupId>
- <artifactId>generateClasses</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>war</packaging>
- <dependencies>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- <version>3.4.0</version>
- </dependency>
- <dependency>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-core</artifactId>
- <version>1.3.2</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <!-- mybatis-generator -->
- <plugin>
- <groupId>org.mybatis.generator</groupId>
- <artifactId>mybatis-generator-maven-plugin</artifactId>
- <version>1.3.2</version>
- <configuration>
- <verbose>true</verbose>
- <overwrite>true</overwrite>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </project></span>
创建generatorConfig.xml(src/java/resources)
- <span style="font-size:14px;"><?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="C:\external common jars\mysql-connector-java-5.1.26-bin.jar" />
- <context id="context1" targetRuntime="MyBatis3">
- <jdbcConnection driverClass="com.mysql.jdbc.Driver"
- connectionURL="jdbc:mysql://localhost:3306/springstud?useUnicode=true&characterEncoding=UTF-8"
- userId="mysql" password="mysql" />
- <javaModelGenerator targetPackage="org.liyb.mybatis.model"
- targetProject="src\main\java" />
- <sqlMapGenerator targetPackage="org.liyb.mybatis.dao"
- targetProject="src\main\resources" />
- <javaClientGenerator targetPackage="org.liyb.mybatis.dao"
- targetProject="src\main\java" type="XMLMAPPER" />
- <table schema="CL_DEMO" tableName="tb_user" />
- </context>
- </generatorConfiguration></span>
先执行maven install命令,然后执行mvn mybatis-generator:generate命令,如果是集成环境直接执行mybatis-generator:generate。
最终将生成一下文件:
以上就是利用generrator工具生成的标准mybaits开发环境的配置代码和目录结构,在此基础上完成我们学习和探究。
看完打开支付宝扫一扫领个红包吧!
![](https://files.cnblogs.com/files/shihaiming/zhifubao_red.gif)