Mybatis generator 逆向生成代码

简单介绍

本文介绍用mybatis逆向生成javaben dao接口

1.创建maven项目 创建相应的包

附上项目创建完成的图片

然后在pom.xml文件里面引入需要的jar的依赖

<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/maven-v4_0_0.xsd">;
<modelVersion>4.0.0</modelVersion>
<groupId>com.xx</groupId>
<artifactId>Mybaits</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Mybaits Maven Webapp</name>
<url>http://maven.apache.org</url>;
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>

org.mybatis mybatis 3.4.0 org.mybatis.generator mybatis-generator-core 1.3.5 com.oracle ojdbc6 0.0.1-SNAPSHOT Mybaits 然后在src/main/resources下创建generator所需的配置文件 配置文件里面有些地方需要改动,需要的朋友可以根据自己的情况改动 在这附上配置文件内容
复制代码 然后在com.test包下创建逆向生成的启动java文件 启动文件内容看下面的代码 复制代码 package com.test; import java.io.File; import java.util.ArrayList; import java.util.List; 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; public class Test { public static void main(String[] args) throws Exception { List warnings = new ArrayList (); boolean overwrite = true; // 配置文件路径切记写对 File configFile = new File("src/main/resources/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); } } 配置文件写完之后直接运行此配置文件,就可以生成代码,下面附上生成之后的效果(运行完之后,刷新项目 就可以看到生成的文件) 文章中涉及到的配置文件,启动类等都可以在mybatis官网找到。 如有错误,请大神指导。

猜你喜欢

转载自blog.51cto.com/13932491/2312738