Mybatis generator

Mybatis generator

mybatis代码自动生成基本增、删、改、查

1、pom.xml

<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>springboot</groupId>
  <artifactId>first</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>first Maven Webapp</name>
  <url>http://maven.apache.org</url>
  
	<build>
		<finalName>first</finalName>
		<plugins>
			<!--MG的插件-->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.3</version>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.42</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <!--配置文件的路径-->
                    <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
                    <!--允许移动生成的文件-->
                    <verbose>true</verbose>
                    <!--允许覆盖生成的文件-->
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
		</plugins>
	</build>
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<start-class>com.tecpie.TecpieApplication</start-class>
		<!-- 编译jdk版本 -->
		<java.version>1.8</java.version>
		<druid.version>1.1.4</druid.version>
	</properties>
	<parent>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-parent</artifactId>
	    <version>1.4.7.RELEASE</version>
	</parent>
	<dependencies>
	    <dependency>
	        <groupId>org.springframework.boot</groupId>
	        <artifactId>spring-boot-starter-web</artifactId>
	    </dependency>
	    <!-- 引入freeMarker的依赖包. -->  
	    <dependency>     
	        <groupId>org.springframework.boot</groupId>    
	        <artifactId>spring-boot-starter-freemarker</artifactId>  
	    </dependency>
	    <dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jdbc</artifactId>
		</dependency>
		
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>1.1.1</version>
		</dependency>
<!-- DB Start -->	
	<!-- 自动生成Entity(Model) Start-->
		<dependency>
		    <groupId>org.mybatis.generator</groupId>
		    <artifactId>mybatis-generator-core</artifactId>
		    <version>1.3.5</version>
		</dependency>
	<!-- 自动生成Entity(Model) End-->	
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>${druid.version}</version>
		</dependency>
		
<!-- DB End -->
<!-- Shiro Start -->
		<dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-spring</artifactId>
            <version>1.2.6</version>
        </dependency>	
<!-- Shiro End -->	
<!-- Utils Start -->
		<!-- java分页插件 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper</artifactId>
			<version>4.1.6</version>
		</dependency>
        <!-- fastjson -->
        <dependency>
		    <groupId>com.alibaba</groupId>
		    <artifactId>fastjson</artifactId>
		    <version>1.2.38</version>
		</dependency>
<!-- Utils End -->
	</dependencies>
	
</project>



2、generatorConfig.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- ~ The MIT License (MIT) ~ ~ Copyright (c) 2014 abel533@gmail.com ~ ~
	Permission is hereby granted, free of charge, to any person obtaining a copy
	~ of this software and associated documentation files (the "Software"), to
	deal ~ in the Software without restriction, including without limitation
	the rights ~ to use, copy, modify, merge, publish, distribute, sublicense,
	and/or sell ~ copies of the Software, and to permit persons to whom the Software
	is ~ furnished to do so, subject to the following conditions: ~ ~ The above
	copyright notice and this permission notice shall be included in ~ all copies
	or substantial portions of the Software. ~ ~ THE SOFTWARE IS PROVIDED "AS
	IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ~ IMPLIED, INCLUDING BUT NOT
	LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ~ FITNESS FOR A PARTICULAR
	PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ~ AUTHORS OR COPYRIGHT
	HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ~ LIABILITY, WHETHER IN
	AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ~ OUT OF OR IN CONNECTION
	WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ~ THE SOFTWARE. -->

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

<generatorConfiguration>
	
	<!-- 引入Properties文件 -->
	<properties resource="application-dev.properties" />
	
	<!-- 在 pom.xml 插件(plugin)中添加了mysql-connerctor 就不需要下面的classPathEntry -->
<!-- 	<classPathEntry location="D:\xiecong\mavenRepository\mysql\mysql-connector-java\5.1.42\mysql-connector-java-5.1.42.jar"/>  -->
	
	<context id="generatorSql" defaultModelType="flat">
		<property name="beginningDelimiter" value="`" />
		<property name="endingDelimiter" value="`" />

	    <commentGenerator>  
	    	<!-- 这个元素用来去除指定生成的注释中是否包含生成的日期 false:表示保护 -->
            <!-- 如果生成日期,会造成即使修改一个字段,整个实体类所有属性都会发生变化,不利于版本控制,所以设置为true -->
	        <property name="suppressDate" value="true"/>  
	        <!-- 是否去除自动生成的注释 true:是 : false:否 -->  
	        <property name="suppressAllComments" value="true"/>  
	    </commentGenerator>  

		<!-- 数据库地址 -->
		<jdbcConnection driverClass="${spring.datasource.driver-class-name}"
			connectionURL="${spring.datasource.url}" 
			userId="${spring.datasource.username}"
			password="${spring.datasource.password}">
		</jdbcConnection>

		<javaTypeResolver type="org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl">
			<!--
                true:使用BigDecimal对应DECIMAL和 NUMERIC数据类型
                false:默认,
                    scale>0;length>18:使用BigDecimal;
                    scale=0;length[10,18]:使用Long;
                    scale=0;length[5,9]:使用Integer;
                    scale=0;length<5:使用Short;
             -->
			<property name="forceBigDecimals" value="false"/>
		</javaTypeResolver>
		
		<!-- 生成Entity位置 -->
		<javaModelGenerator targetPackage="com.tecpie.model" targetProject="./src/main/java" />
		
		<!-- 生成 *Mapper.xml位置 -->
		<sqlMapGenerator targetPackage="com.tecpie.mapper" targetProject="./src/main/java"/>

		<!-- 生成 *Mapper.java位置 -->
		<javaClientGenerator targetPackage="com.tecpie.dao" targetProject="./src/main/java" type="XMLMAPPER"/>
		
		<table tableName="sys_t_user" domainObjectName="UserEntity" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
			<!--<columnOverride column="project_id" property="id" />-->
		</table>
		<table tableName="sys_t_role" domainObjectName="RoleEntity" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
			<!--<columnOverride column="project_id" property="id" />-->
		</table>
		<table tableName="sys_t_permission" domainObjectName="PermissionEntity" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
			<!--<columnOverride column="project_id" property="id" />-->
		</table>
	</context>
</generatorConfiguration>

注:生成位置可更改

3、maven build



golas: mybatis-generator:generate

4、效果




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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值