上次是进行了一个定时器任务的操作,这次进行Mybatis三剑客插件的使用。
主要任务:安装Mybatis插件
Mybatis-plugin插件
步骤如下:
①Help—Eclipse Marketplace
②在搜索框中搜Mybatis,找到如下版本的插件,点击Install
③点击confirm
④选择接受
⑤出现警告,选择OK
⑥选择Yes,重启Eclipse
OK,插件我们配置完成了
接下来我们来使用此插件
-
要查找某一个方法,在dao接口中某一个方法中 按住 Ctrl键 鼠标指到方法名称上 选择open xml 就会自动跳转
-
编辑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
- 引入jar包
- 配置:mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//E