Mybatis自动生成代码

1、配置文件(放在项目下即可)


PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">












connectionURL="jdbc:mysql://localhost:3306/testapp?useUnicode=true&characterEncoding=utf8&
useSSL=false&serverTimezone=GMT"
userId="root"
password="123456">







targetProject="./src/main/java">





targetProject="./src/main/resources">




targetProject="./src/main/java">


enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false" selectByExampleQueryId="false">


enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false" selectByExampleQueryId="false">

enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false" selectByExampleQueryId="false">



2、执行文件

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
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.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

public class RunMybatisGenerator {
public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
//此文件直接执行即可
List warnings = new ArrayList();
boolean overwrite = true;
//这个xml文件放在项目下就可以
File configFile = new File("MybagisGenerator.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);
}
}

 

转载于:https://www.cnblogs.com/itxiaoxia/p/11446854.html

你可能感兴趣的:(java,数据库)