Mybatis generator使用小记

Mybatis generator可以使用命令行,eclipse插件和maven配置实现自动生成代码的功能,主要来看看使用eclipse插件生成代码方法。

先安装插件:

 

 

 

 

maven加载mysql驱动:

<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>com</groupId>
  <artifactId>mybatis</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>mybatis</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.27</version>
        </dependency>
  </dependencies>
</project>

 

 

安装完成后新建一个xml文件:

 

 

我的项目结构:

 

 

 

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="context1">
    <jdbcConnection connectionURL="jdbc:mysql://192.168.115.72:8066/simanage?useUnicode=true&amp;characterEncoding=utf-8&amp;zeroDateTimeBehavior=convertToNull" driverClass="com.mysql.jdbc.Driver" password="test" userId="mycat" />
    <javaModelGenerator targetPackage="com.mybatis.model" targetProject="mybatis/src/main/java" />
    <sqlMapGenerator targetPackage="com.mybatis.mapper" targetProject="mybatis/src/main/java" />
    <javaClientGenerator targetPackage="com.mybatis.dao" targetProject="mybatis/src/main/java" type="XMLMAPPER" />
    <table schema="" tableName="T_SI_STATISFACTION_ANSWER_DETAIL">
    </table>
  </context>
</generatorConfiguration>

最后直接run as-->run mybatis generator即可生成代码。

 

posted @ 2019-01-03 17:01  Lost blog  阅读(286)  评论(0编辑  收藏  举报