零、起因
- 后端开发少不了设计表(例如:xxx表)。
- 设计好表后,少不了需要去实现xxxDO、xxxMapper.java、xxxMapper.xml(ORM框架选Mybatis的情况)。
- 【解决办法】:利用“Free MyBatis Tool插件”消灭dao层的繁琐编码。

一、怎么使用Free MyBatis Tool插件?
1 基本使用

2 进阶使用(搞清楚Options的用法)
2.1 概览
- Use-Lombok
- Comment(实体注释)
- Use-Schema(使用Schema前缀)
- Overwrite-Java
- Overwrite-Xml
- Repository-Annotation(Repository注解)
- toString/hashCode/equals
- Parent-Interface(Dao公共父接口)
- JSR310:Date and Time API
- JPA-Annotation(JPA注解)
- Actual-Column(实际的列名)
- Use-Alias(启用别名查询)
- Use-Example
- Page(分页,需开启Use-Example)
- Add-ForUpdate(需开启Use-Example)
2.2 详述
2.2.0 Options(一项都不勾选)
package com.forrest.demo.model;
import java.io.Serializable;
import java.util.Date;
public class UserDO implements Serializable {
private Integer id;
private String username;
private String passwordHash;
private String email;
private Date registrationDate;
private Date lastLoginTime;
private static final long serialVersionUID = 1L;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPasswordHash() {
return passwordHash;
}
public void setPasswordHash(String passwordHash) {
this.passwordHash = passwordHash;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public Date getRegistrationDate() {
return registrationDate;
}
public void setRegistrationDate(Date registrationDate) {
this.registrationDate = registrationDate;
}
public Date getLastLoginTime() {
return lastLoginTime;
}
public void setLastLoginTime(Date lastLoginTime) {
this.lastLoginTime = lastLoginTime;
}
}
package com.forrest.demo.dao;
import com.forrest.demo.model.UserDO;
public interface UserMapper {
int deleteByPrimaryKey(Integer id);
int insert(UserDO record);
int insertSelective(UserDO record);
UserDO selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(UserDO record);
int updateByPrimaryKey(UserDO record);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.forrest.demo.dao.UserMapper">
<resultMap id="BaseResultMap" type="com.forrest.demo.model.UserDO">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="username" jdbcType="VARCHAR" property="username" />
<result column="password_hash" jdbcType="VARCHAR" property="passwordHash" />
<result column="email" jdbcType="VARCHAR" property