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&characterEncoding=utf-8&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即可生成代码。
作者: lost blog
出处: http://www.cnblogs.com/JAYIT/
关于作者:专注服务器端开发
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接 如有问题, 可邮件(sawyershaw@qq.com)咨询.