创建表
CREATE TABLE `t_qingjia` (
`id` VARCHAR(32) NOT NULL COLLATE 'utf8mb4_general_ci',
`desc` VARCHAR(128) NULL DEFAULT NULL COMMENT '请假原因' COLLATE 'utf8mb4_general_ci',
`day` FLOAT NULL DEFAULT NULL COMMENT '请假天数,可以请半天假',
`emp` VARCHAR(64) NULL DEFAULT NULL COMMENT '员工姓名' COLLATE 'utf8mb4_general_ci',
`approved_txt` VARCHAR(128) NULL DEFAULT NULL COMMENT '审批意见' COLLATE 'utf8mb4_general_ci',
`approved` INT NULL DEFAULT NULL COMMENT '审批结果,0:默认值,1:同意,2:拒绝',
`approved_time` DATETIME NULL DEFAULT NULL COMMENT '审批时间',
`act_pid` VARCHAR(64) NULL DEFAULT NULL COMMENT 'flowable的pid' COLLATE 'utf8mb4_general_ci',
`create_time` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
;
Mybatis相关
下面代码是通过 Mybatis代码生成器 创建的
创建实体类
创建类:top.malaoshi.entity.Qingjia,内容如下:
package top.malaoshi.entity;
import java.io.Serializable;
import java.util.Date;
/**
* @author
*
*/
public class Qingjia implements Serializable {
private String id;
/**
* 请假原因
*/
private String desc;
/**
* 请假天数,可以请半天假
*/
private Float day;
/**
* 员工姓名
*/
private String emp;
/**
* 审批结果,0:默认值,1:同意,2:拒绝
*/
private Integer approved;
/**
* flowable的pid
*/
private String actPid;
private String approvedTxt;
private Date createTime;
private Date approvedTime;
public Date getApprovedTime() {
return approvedTime;
}
public void setApprovedTime(Date approvedTime) {
this.approvedTime = approvedTime;
}
public String getApprovedTxt() {
return approvedTxt;
}
public void setApprovedTxt(String approvedTxt) {
this.approvedTxt = approvedTxt;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
private static final long serialVersionUID = 1L;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Float getDay() {
return day;
}
public void setDay(Float day) {
this.day = day;
}
public String getEmp() {
return emp;
}
public void setEmp(String emp) {
this.emp = emp;
}
public Integer getApproved() {
return approved;
}
public void setApproved(Integer approved) {
this.approved = approved;
}
public String getActPid() {
return actPid;
}
public void setActPid(String actPid) {
this.actPid = actPid;
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Qingjia other = (Qingjia) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getDesc() == null ? other.getDesc() == null : this.getDesc().equals(other.getDesc()))
&& (this.getDay() == null ? other.getDay() == null : this.getDay().equals(other.getDay()))
&& (this.getEmp() == null ? other.getEmp() == null : this.getEmp().equals(other.getEmp()))
&& (this.getApproved() == null ? other.getApproved() == null : this.getApproved().equals(other.getApproved()))
&& (this.getActPid() == null ? other.getActPid() == null : this.getActPid().equals(other.getActPid()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getDesc() == null) ? 0 : getDesc().hashCode());
result = prime * result + ((getDay() == null) ? 0 : getDay().hashCode());
result = prime * result + ((getEmp() == null) ? 0 : getEmp().hashCode());
result = prime * result + ((getApproved() == null) ? 0 : getApproved().hashCode());
result = prime * result + ((getActPid() == null) ? 0 : getActPid().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", desc=").append(desc);
sb.append(", day=").append(day);
sb.append(", emp=").append(emp);
sb.append(", approved=").append(approved);
sb.append(", actPid=").append(actPid);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
创建 dao
创建接口:top.malaoshi.mapper.MyBatisBaseDao,内容如下:
package top.malaoshi.mapper;
import java.io.Serializable;
/**
* DAO公共基类,由MybatisGenerator自动生成请勿修改
* @param <Model> The Model Class 这里是泛型不是Model类
* @param <PK> The Primary Key Class 如果是无主键,则可以用Model来跳过,如果是多主键则是Key类
*/
public interface MyBatisBaseDao<Model, PK extends Serializable> {
int deleteByPrimaryKey(PK id);
int insert(Model record);
int insertSelective(Model record);
Model selectByPrimaryKey(PK id);
int updateByPrimaryKeySelective(Model record);
int updateByPrimaryKey(Model record);
}
创建 mapper
创建接口:top.malaoshi.mapper.QingjiaMapper,内容如下:
package top.malaoshi.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import top.malaoshi.entity.Qingjia;
import java.util.List;
/**
* QingjiaMapper继承基类
*/
//@Repository
@Mapper
public interface QingjiaMapper extends MyBatisBaseDao<Qingjia, String> {
public List<Qingjia> daiban(List list);
}
创建 mapper.xml
创建文件:resources/mybatis/mapper/QingjiaMapper.xml,内容如下:
<?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="top.malaoshi.mapper.QingjiaMapper">
<resultMap id="BaseResultMap" type="top.malaoshi.entity.Qingjia">
<id column="id" property="id" />
<result column="desc" jdbcType="VARCHAR" property="desc" />
<result column="day" jdbcType="REAL" property="day" />
<result column="emp" jdbcType="VARCHAR" property="emp" />
<result column="approved" jdbcType="INTEGER" property="approved" />
<result column="act_pid" jdbcType="VARCHAR" property="actPid" />
<result column="approved_txt" property="approvedTxt" />
<result column="create_time" property="createTime" />
<result column="approved_time" property="approvedTime" />
</resultMap>
<sql id="Base_Column_List">
id, `desc`, `day`, emp, approved, act_pid
</sql>
<sql id="select_all_column">
id, `desc`, `day`, emp, approved_txt,approved, act_pid,create_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_qingjia
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" >
delete from t_qingjia
where id = #{id,jdbcType=BIGINT}
</delete>
<insert id="insert" parameterType="top.malaoshi.entity.Qingjia">
insert into t_qingjia (id, `desc`, `day`, emp,
approved, act_pid)
values (#{id,jdbcType=BIGINT}, #{desc,jdbcType=VARCHAR}, #{day,jdbcType=REAL}, #{emp,jdbcType=VARCHAR},
#{approved,jdbcType=INTEGER}, #{actPid,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="top.malaoshi.entity.Qingjia">
insert into t_qingjia
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="desc != null">
`desc`,
</if>
<if test="day != null">
`day`,
</if>
<if test="emp != null">
emp,
</if>
<if test="approved != null">
approved,
</if>
<if test="actPid != null">
act_pid,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=BIGINT},
</if>
<if test="desc != null">
#{desc,jdbcType=VARCHAR},
</if>
<if test="day != null">
#{day,jdbcType=REAL},
</if>
<if test="emp != null">
#{emp,jdbcType=VARCHAR},
</if>
<if test="approved != null">
#{approved,jdbcType=INTEGER},
</if>
<if test="actPid != null">
#{actPid,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="top.malaoshi.entity.Qingjia">
update t_qingjia
<set>
<if test="desc != null">
`desc` = #{desc,jdbcType=VARCHAR},
</if>
<if test="day != null">
`day` = #{day,jdbcType=REAL},
</if>
<if test="emp != null">
emp = #{emp,jdbcType=VARCHAR},
</if>
<if test="approved != null">
approved = #{approved,jdbcType=INTEGER},
</if>
<if test="approvedTxt != null">
approved_txt = #{approvedTxt},
</if>
<if test="approvedTime != null">
approved_time = #{approvedTime},
</if>
<if test="actPid != null">
act_pid = #{actPid,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="top.malaoshi.entity.Qingjia">
update t_qingjia
set `desc` = #{desc,jdbcType=VARCHAR},
`day` = #{day,jdbcType=REAL},
emp = #{emp,jdbcType=VARCHAR},
approved = #{approved,jdbcType=INTEGER},
act_pid = #{actPid,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
<select id="daiban" resultMap="BaseResultMap">
select id, `day`, emp ,approved, act_pid,create_time
from t_qingjia
where
act_pid in
<foreach collection="list" open="(" close=")" item="it" separator=",">
#{it}
</foreach>
</select>
</mapper>
测试
重启服务,如果没有报错,大概率说明成功