JAVA懒开发:mybatis-generator安装和使用(spring-tool-suite)

java懒开发:mybatis-generator根据数据库中表的设计生成对应的实体类,xml Mapper文件,接口以及帮助类。

以spring-tool-suite-3.9.2.RELEASE为例:

安装

打开Help →Eclipse Marketplace 

引入包

<dependency>
	<groupId>org.mybatis.generator</groupId>
	<artifactId>mybatis-generator-core</artifactId>
	<version>1.3.6</version>
</dependency>

创建mybatis-generator配置文件


修改mybatis-generator配置文件

<?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="prod">
        <!-- RowBounds pagination -->
        <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" />
        <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
        <commentGenerator>
            <property name="suppressDate" value="true" />
            <property name="suppressAllComments" value="true" />
        </commentGenerator>

        <!-- jdbc连接 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://192.168.1.206/testOne" userId="root"
            password="1234" />
            
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		
		<!-- targetProject:生成PO类的位置 -->
        <javaModelGenerator targetPackage="com.lazy.develop.generator.entity" targetProject="lazyDevelop">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
			<property name="enableSubPackages" value="false" />
			<!-- 从数据库返回的值被清理前后的空格 -->
			<property name="trimStrings" value="true" />
			<property name="comments" value="true"/>
        </javaModelGenerator>

        <!-- targetProject:mapper映射文件生成的位置 -->
		<sqlMapGenerator targetPackage="com.lazy.develop.generator.mapper"  targetProject="lazyDevelop">
			<property name="enableSubPackages" value="false" />
		</sqlMapGenerator>
		
		<!-- targetPackage:mapper接口生成的位置 -->
		<javaClientGenerator type="XMLMAPPER" targetPackage="com.lazy.develop.generator.dao"  targetProject="lazyDevelop">
			<property name="enableSubPackages" value="false" />
		</javaClientGenerator>
		
		<!-- 指定数据库表 -->
		<table schema="" tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" 
		  enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
			<generatedKey column="id" sqlStatement="MySql" identity="true"/>
		</table>
    </context>
</generatorConfiguration>

项目搭建就不在写了哈,融入自己的框架就Ok了

运行

        如果你编辑器有插件,直接mybatis-generator配置文件右键运行就好了,如果木有运行下面main方法:

package com.mybatis.test;

import org.mybatis.generator.api.ShellRunner;

public class App {

    public static void main(String[] args) {
        args = new String[] { "-configfile", "src\\main\\resources\\generatorConfig.xml.xml", "-overwrite" };
        ShellRunner.main(args);
    }

}

★更多JAVA懒开发、源码请关注:https://my.oschina.net/bianxin/blog/1612024

转载于:https://my.oschina.net/bianxin/blog/1611950

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值