在Eclipes里安装Mybaties

一、利用maven配置jar就引入依赖

详情地址

二、手动引入jar包

在这里插入图片描述

三、generatorConfig.xml

1. 运行配置文件就能自动生成pojo和mapper

2. 生成generatorConfig.xml

项目右键→new→other→myba… 下边的文件,next。。。

在这里插入图片描述

配置文件

<?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>

	<!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包 -->
	<classPathEntry location="E:\Mybatis\mysql-connector-java-5.1.38.jar" />
	
	<!-- targetRuntime 
		 	MyBatis3 :默认的值,生成基于MyBatis3.X以上版本的内容 包括XXXBySample;
		 	MyBatis3Simpl :类似于MyBatis3 但是不生成XXXBySample -->
	
    <context id="mysql" targetRuntime="MyBatis3Simple">
    
   		<commentGenerator>
			<property name="suppressDate" value="true" />
			<!-- 是否去除自动生成的注释 true是/false否 -->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>
		
		<!--数据库链接URL,用户名、密码 -->
		<jdbcConnection driverClass="com.mysql.jdbc.Driver"
			connectionURL="jdbc:mysql://localhost:3306/pingpang" userId="root" password="1234">
		</jdbcConnection>
		
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false" />
		</javaTypeResolver>
		
		<!-- 设置实体类所在的项目与包的位置 -->
		<javaModelGenerator targetPackage="com.bian.pojo" targetProject="MybatiesTest\src">
			<!-- <property name="enableSubPackages" value="true" />
			<property name="trimStrings" value="true" /> -->
		</javaModelGenerator>
		
		<!-- 生成映射文件的包名和位置 -->
		<sqlMapGenerator targetPackage="com.bian.mapper" targetProject="MybatiesTest\src">
			<!-- <property name="enableSubPackages" value="true" /> -->
		</sqlMapGenerator>
		
		<!-- 生成DAO的包名和位置 -->
		<javaClientGenerator targetPackage="com.bian.mapper" targetProject="MybatiesTest\src" type="XMLMAPPER">
			<!-- <property name="enableSubPackages" value="true" /> -->
		</javaClientGenerator>

		<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名 -->
		<table schema="bian" tableName="adress" domainObjectName="Adress">
			是否使用表中的列表生成类中的成员变量名
			<property name="useActualColumnNames" value="false"/>
		</table> 
		
		<!-- 场地表 -->
		<table schema="pingpang" tableName="field" domainObjectName="Field">
			<!-- 是否使用表中的列表生成类中的成员变量名 -->
			<property name="useActualColumnNames" value="false"/>
		</table>
		
		<!-- 财务表 -->
		<table schema="pingpang" tableName="finance" domainObjectName="Finance">
			<!-- 是否使用表中的列表生成类中的成员变量名 -->
			<property name="useActualColumnNames" value="false"/>
		</table>
		
		<!-- 权限表 -->
		<table schema="pingpang" tableName="rule" domainObjectName="Rule">
			<!-- 是否使用表中的列表生成类中的成员变量名 -->
			<property name="useActualColumnNames" value="false"/>
		</table>
		
		<!-- 角色表 -->
		<table schema="pingpang" tableName="role" domainObjectName="Role">
			<!-- 是否使用表中的列表生成类中的成员变量名 -->
			<property name="useActualColumnNames" value="false"/>
		</table>
		
		<!-- 角色——权限联合查询表 -->
		<table schema="pingpang" tableName="rule_role" domainObjectName="Rule_Role">
			<!-- 是否使用表中的列表生成类中的成员变量名 -->
			<property name="useActualColumnNames" value="false"/>
		</table>
		
		<!-- 开台表 -->
		<table schema="pingpang" tableName="table" domainObjectName="Table">
			<!-- 是否使用表中的列表生成类中的成员变量名 -->
			<property name="useActualColumnNames" value="false"/>
		</table>
		
		<!-- 员工表 -->
		<table schema="pingpang" tableName="user" domainObjectName="User">
			<!-- 是否使用表中的列表生成类中的成员变量名 -->
			<property name="useActualColumnNames" value="false"/>
		</table>
    </context>
</generatorConfiguration>
1、这是Eclipse MyBatis generator 1.3.7插件的核心包 2、首先到Eclipse中下载 MyBatis Generator 1.3.7插件,下载完按步骤进行安装 打开Help > Eclipse Marketplace > Search > 输入框输入 MyBatis Generator 1.3.7 搜索 > Install 3、安装完之后重启Eclipse 然后在File > New > Other > 搜索MyBatis 会看到此插件,说明已经安装成功 4、此时我们创建一个 generatorConfig.xml 填写好各种配置(详细请看generatorConfig.xml)右键 > Run,实体类生成成功, 但是我们发现实体类、Dao、Mapper.xml 中的注释都是英文不是我们想要的中文注释,此时需要我们把刚下载的MyBatis Generator插件核心包 替换掉Eclipse安装好的MyBatis Generator插件核心包 替换步骤: 1>、打开Eclipse安装目录打开plugins文件夹找到org.mybatis.generator.core_1.3.7.201807042148.jar D:\tools\eclipse\plugins\org.mybatis.generator.core_1.3.7.201807042148.jar 2>、把刚下载的org.mybatis.generator.core_1.3.7.201807042148.jar替换掉旧的org.mybatis.generator.core_1.3.7.201807042148.jar 注意:新的jar名称必须和旧的jar名称相同 5、替换完之后重启Eclipse,再次配置好generatorConfig.xml 右键 > Run,实体类生成成功,次时我们打开实体类发现 已经有了中文注释 实体类中文注释:类名称、属性名称、方法名称、作者、版本号 Dao类注释:基本的增删改查方法注释 注意:实体类的注释都是映射的数据库表中的注释,如果数据库表和字段没有注释则生成的实体类也没有注释 6、此jar包也适用于MyBatis generator 1.3.6版本 替换步骤同上 (亲测绝对可以使用)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值