Mybatis三剑客插件

本文介绍了如何安装和使用Mybatis的三款插件:Mybatis-plugin,Mybatis-PageHelper和Mybatis-generator。通过详细步骤演示了从安装插件到配置、使用的过程,包括在Eclipse中安装Mybatis-plugin,使用快捷键增强XML编辑体验,以及利用Mybatis-PageHelper实现分页功能。同时,还展示了Mybatis-generator自动生成代码的方法。
摘要由CSDN通过智能技术生成

上次是进行了一个定时器任务的操作,这次进行Mybatis三剑客插件的使用。


主要任务:安装Mybatis插件


Mybatis-plugin插件

步骤如下:
①Help—Eclipse Marketplace
在这里插入图片描述②在搜索框中搜Mybatis,找到如下版本的插件,点击Install
在这里插入图片描述
③点击confirm
在这里插入图片描述
④选择接受
在这里插入图片描述
⑤出现警告,选择OK
在这里插入图片描述
⑥选择Yes,重启Eclipse
在这里插入图片描述

OK,插件我们配置完成了
接下来我们来使用此插件

  1. 要查找某一个方法,在dao接口中某一个方法中 按住 Ctrl键 鼠标指到方法名称上 选择open xml 就会自动跳转

  2. 编辑XML文件时自动补全,自动生成resultMap 安装键盘 alt + / 会弹出提示框

①在UserDao.xml中的<mapper>后面书写如下代码

	<resultMap type="com.lf.model.User" id="userMap">
		<result property="id" column="id" /><!-- colum是数据库字段的名字 propertiy是java里面的属性 -->
		<result property="username" column="username" /><!-- colum是数据库字段的名字 propertiy是java里面的属性 -->
		<result property="pwd" column="pwd" /><!--Mybatis plugin插件快捷键Alt+/  -->
		<result property="realname" column="realname" />
		<result property="grade" column="grade" />
		<result property="total" column="total" />
		<result property="account" column="account" />
	</resultMap>

②在UserDao.xml中的第一个<select>修改如下:

	<select id="findById" parameterType="integer" resultMap="userMap">
		select * from user where id = #{id}
	</select>

Mybatis-PageHelper分页

中文文档https://github.com/pagehelper/MybatisPageHelper/blob/master/wikis/zh/HowToUse.md

  1. 引入jar包
    在这里插入图片描述
  2. 配置:mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//E
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值