generator逆向工程

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <groupId>com.rayc</groupId>
    <artifactId>generator</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <!-- mybatis 依赖(让生成的 pojo 和 mapper 不缺少注解相关类型) -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <!-- mybatis generator plugin 依赖 -->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.7</version>
                <configuration>
                    <verbose>true</verbose>
                    <!-- 是否覆盖 -->
                    <overwrite>true</overwrite>
                    <!-- 自动生成的配置 -->
                    <configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
                </configuration>
                <dependencies>
                    <!-- mybatis generator core 依赖 -->
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.7</version>
                    </dependency>

                    <!-- mysql 数据库依赖 -->
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>8.0.18</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
</project>

mybatis-generator.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="MysqlTables" targetRuntime="MyBatis3">
		<!-- 生成的Java文件的编码 -->
		<property name="javaFileEncoding" value="UTF-8"/>
		<!-- 增加Models ToStirng方法 -->
		<plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
		<!-- 增加Models Serializable实现 -->
		<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>

		<!-- 分页插件 -->
		<!-- 在example类中增 page 属性,并在mapper.xml的查询中加入page !=null 时的查询 -->
		<!-- <plugin type="org.mybatis.generator.plugins.MySQLPagerPlugin" /> -->
		<!-- 在example类中增 offset和limit属性,并在mapper.xml的查询中加入limit ${offset} , ${limit} 提供在offset和limit>0时的查询 -->
		<!-- <plugin type="org.mybatis.generator.plugins.MySQLPaginationPlugin"></plugin> -->

		<!-- 是否去除自动生成的注释 true:是 : false:否,注释为英文默认去掉注释 -->
		<!-- type指定生成注释使用的对象  -->
		<commentGenerator>
			<property name="suppressAllComments" value="true"/>
		</commentGenerator>

		<!-- mysql数据库连接配置 -->
		<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
		                connectionURL="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai&amp;tinyInt1isBit=false"
		                userId="root" password="">
		</jdbcConnection>

		<!--
			是否忽略BigDecimals 非必填项
				自动生成Java对象的时候,会根据number类型的长度不同生成不同的数据类型
					number长度   Java类型
					1~4          Short
					5~9          Integer
					10~18        Long
					18+          BigDecimal
		 -->
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false"/>
		</javaTypeResolver>

		<!-- 以下内容,需要改动 -->
		<!-- java类生成的位置  -->
		<javaModelGenerator targetPackage="com.generator.pojo" targetProject="src/main/java">
			<!-- 在targetPackage的基础上,根据数据库的schema再生成一层package,最终生成的类放在这个package下,默认为false -->
			<property name="enableSubPackages" value="false"/>
			<!-- 从数据库返回的值去除前后空格 -->
			<property name="trimStrings" value="true"/>
		</javaModelGenerator>

		<!-- *Mapper.xml配置文件生成的位置 -->
		<sqlMapGenerator targetPackage="com.generator.mapper" targetProject="src/main/java">
			<!-- 是否让schema作为包后缀 -->
			<property name="enableSubPackages" value="false"/>
		</sqlMapGenerator>

		<!-- java mapper接口生成的位置(interface) -->
		<javaClientGenerator type="XMLMAPPER" targetPackage="com.generator.mapper" targetProject="src/main/java">
			<!-- 是否让schema作为包后缀 -->
			<property name="enableSubPackages" value="false"/>
		</javaClientGenerator>

		<!--
			指定数据库表
				tableName数据库表名
				domainObjectName生成的实体类名
				是否需要mapper配置文件加入sql的where条件查询,需要将enableCountByExample等设为true,会生成一个对应domainObjectName的Example类
		 -->
		<table tableName="ks_blog" domainObjectName="Blog"
		       enableCountByExample="false" enableDeleteByExample="false"
		       enableSelectByExample="false" enableUpdateByExample="false">
			<!-- 用于insert时,返回主键的编号 -->
			<generatedKey column="id" sqlStatement="MySql" identity="true"/>
		</table>
	</context>
</generatorConfiguration>

可先install 再运行插件,生成mapper及pojo
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值