MyBatis中XXMapper示例记录

XXMapper.xml的结构示例如下,包括<resultMap>、<id>、<result>、<select>、<update>、<foreach>、<if>标签的使用:

<?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.cmit.kapok.activiti.mapper.ActKapWorkConfMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.cmit.kapok.system.entity.activiti.ActKapWorkConf">
        <id column="id" property="id" />
        <result column="work_conf_name" property="workConfName" />
        <result column="work_type" property="workType" />
        <result column="work_conf_code" property="workConfCode" />
        <result column="work_status" property="workStatus" />
        <result column="limit_num" property="limitNum" />
        <result column="proc_def_id" property="procDefId" />
        <result column="auth_status" property="authStatus" />
        <result column="create_person_id" property="createPersonId" />
        <result column="create_user_name" property="createUserName" />
        <result column="create_person_name" property="createPersonName" />
        <result column="create_time" property="createTime" />
        <result column="form_id" property="formId" />
        <result column="order_pre_code" property="orderPreCode" />
        <result column="exec_type" property="execType" />
        <result column="cycle_type" property="cycleType" />
        <result column="week_day" property="weekDay" />
        <result column="month_day" property="monthDay" />
        <result column="year_day" property="yearDay" />
        <result column="work_time" property="workTime" />
        <result column="execute_time" property="executeTime" />
    </resultMap>

    <select id="scanToLaunchWork" resultMap="BaseResultMap">
        SELECT * from act_kap_work_conf where work_status = #{status} and exec_type = #{execType} and execute_time &lt;=  #{time}
    </select>

    <update id="updateStatus">
        UPDATE act_kap_work_conf set work_status = #{status} where id = #{workConfId}
    </update>

    <select id="queryWorkConfList" resultMap="BaseResultMap">
        SELECT
        id,
        work_conf_name,
        work_conf_code,
        work_type,
        work_status,
        limit_num,
        proc_def_id,
        auth_status,
        create_time,
        form_id,
        order_pre_code,
        exec_type,
        cycle_type,
        week_day,
        month_day,
        year_day,
        work_time,
        execute_time
        from act_kap_work_conf
        WHERE work_status IN
        <foreach collection="statusList" item="status" index="index" open="(" close=")" separator=",">
            #{status}
        </foreach>
        <if test="workType != null">
            and work_type = #{workType}
        </if>
        <if test="workConfName != null and workConfName != ''">
            and work_conf_name like concat(concat('%',#{workConfName}),'%')
        </if>
        <if test="userId != null and userId != ''">
            and create_person_id = #{userId}
        </if>
        ORDER BY create_time DESC
    </select>
</mapper>

其对应的XXMapper.java代码为:

package com.cmit.kapok.activiti.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cmit.kapok.system.entity.activiti.ActKapWorkConf;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 
 * @since 2022-03-24
 */
public interface ActKapWorkConfMapper extends BaseMapper<ActKapWorkConf> {

    List<ActKapWorkConf> scanToLaunchWork(@Param("time") Date time, @Param("status") Integer status, @Param("execType") Integer execType);

    void updateStatus(@Param("workConfId") Integer workConfId, @Param("status") Integer status);

    List<ActKapWorkConf> queryWorkConfList(@Param("statusList") List<Integer> statusList, @Param("workConfName") String workConfName,
                                           @Param("workType") Integer workType, @Param("userId") String userId);
}

 

posted @ 2023-04-12 15:38  罗毅豪  阅读(28)  评论(0编辑  收藏  举报