远方蔚蓝
一刹那情真,相逢不如不见

文章数量 126

访问次数 199895

运行天数 1437

最近活跃 2024-10-04 23:36:48

进入后台管理系统

Mybatis逆向工程配置


<?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>
<!-- maven 项目需要配置
	<classPathEntry location="数据库驱动包的路径" />
-->
	<context id="testTables" targetRuntime="MyBatis3">
		<commentGenerator>
			<!-- 是否去除自动生成的注释 true:是 : false:否 -->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/wst_site_prod" userId="root"
			password="root">
		</jdbcConnection>
		<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 
			和 NUMERIC 类型解析为java.math.BigDecimal -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		<!-- targetProject:生成domain类的位置 -->
		<javaModelGenerator targetPackage="wst.st.site.data.entity"
			targetProject=".\src">
			<!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
			<!-- 从数据库返回的值被清理前后的空格 -->
			<property name="trimStrings" value="true" />
		</javaModelGenerator>
		<!-- targetProject:mapper映射文件生成的位置 -->
		<sqlMapGenerator targetPackage="wst.st.site.data.mapper"
			targetProject=".\src">
			<!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>
		<!-- targetPackage:mapper接口生成的位置 -->
		<javaClientGenerator type="XMLMAPPER"
			targetPackage="wst.st.site.data.dao" targetProject=".\src">
			<!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>
		
		<!-- 指定数据库表 -->
		<!-- 
		<table tableName="site_account" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_article" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_article_ext" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_article_type" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_visit_count" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_log" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_user" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="code_country" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="code_area" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_task_trigger" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_task" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_task_group" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_image" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_image_type" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_update" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_sys_config" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_seo_templet" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_comment" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_contact" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		<table tableName="site_visitor_info" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
		</table>
		 -->
		 <table tableName="site_menu" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">   
            <generatedKey column="id" sqlStatement="JDBC" identity="true" /> 
		</table>
		<table tableName="site_roles" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
            <generatedKey column="id" sqlStatement="JDBC" identity="true" /> 
		</table>
		<table tableName="site_role_menu" domainObjectName=""
			enableCountByExample="false" enableSelectByExample="false"
            enableUpdateByExample="false" enableDeleteByExample="false">    
            <generatedKey column="id" sqlStatement="JDBC" identity="true" /> 
		</table>
	</context>
</generatorConfiguration>
<!-- generatedKey用于生成生成主键的方法,
    如果设置了该元素,MBG会在生成的<insert>元素中生成一条正确的<selectKey>元素,该元素可选
    column:主键的列名;
    sqlStatement:要生成的selectKey语句,有以下可选项:
        Cloudscape:相当于selectKey的SQL为: VALUES IDENTITY_VAL_LOCAL()
        DB2       :相当于selectKey的SQL为: VALUES IDENTITY_VAL_LOCAL()
        DB2_MF    :相当于selectKey的SQL为:SELECT IDENTITY_VAL_LOCAL() FROM SYSIBM.SYSDUMMY1
        Derby      :相当于selectKey的SQL为:VALUES IDENTITY_VAL_LOCAL()
        HSQLDB      :相当于selectKey的SQL为:CALL IDENTITY()
        Informix  :相当于selectKey的SQL为:select dbinfo('sqlca.sqlerrd1') from systables where tabid=1
        MySql      :相当于selectKey的SQL为:SELECT LAST_INSERT_ID()
        SqlServer :相当于selectKey的SQL为:SELECT SCOPE_IDENTITY()
        SYBASE      :相当于selectKey的SQL为:SELECT @@IDENTITY
        JDBC      :相当于在生成的insert元素上添加useGeneratedKeys="true"和keyProperty属性
<generatedKey column="" sqlStatement=""/>
 -->
<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>net.togogo</groupId>
  <artifactId>GeneratorPro</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>GeneratorPro 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>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.39</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.4.1</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis.generator</groupId>
      <artifactId>mybatis-generator-core</artifactId>
      <version>1.3.5</version>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.6</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>GeneratorPro</finalName>
    <plugins>
      <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.5</version>
        <configuration>
          <verbose>true</verbose>
          <overwrite>true</overwrite>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
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 GeneratorSqlmap {
	public void generator() throws Exception {
		List<String> warnings = new ArrayList<String>();
		boolean overwrite = true;
		// 指定 逆向工程配置文件
		File configFile = new File("generatorConfig.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);
	}
	public static void main(String[] args) throws Exception {
		try {
			GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
			generatorSqlmap.generator();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
不使用maven导入jar
jsqlparser-0.9.5.jar
log4j-1.2.16.jar
mybatis-3.2.3.jar
mybatis-generator-core-1.3.5.jar
mysql-connector-java-5.1.28-bin.jar
ojdbc14.jar
pagehelper-4.1.4.jar