ProjectsMapper.xml 2.81 KB
<?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.project.demo.mapper.ProjectsMapper">
    <resultMap id="projectsMap" type="com.project.demo.domain.Projects">
        <result column="id" property="id" />
        <result column="name" property="projectName" />
        <result column="users_id" property="usersId" />
        <result column="remark" property="remark" />
        <result column="start_time" property="startTime" />
    </resultMap>

    <select id="search" resultMap="projectsMap" resultType="Map">
        SELECT
          *
        FROM projects
        where 1=1
        <if test="params.projectsIds != null">
            AND id in
            <foreach collection="params.projectsIds" item="item" index="index"
                     open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ORDER BY id desc
    </select>

    <select id="findById" resultMap="projectsMap">
        SELECT
        *
        FROM projects
        where id = #{id}
    </select>

    <select id="findByUsersId" resultMap="projectsMap" resultType="Map">
        SELECT
        *
        FROM projects
        where users_id = #{usersId}
    </select>

    <update id="updateProjects" parameterType="com.project.demo.domain.Projects">
        UPDATE projects
        <set>
            <if test="params.projectName != null">
                name = #{params.projectName},
            </if>
            <if test="params.projectRemark != null">
                remark = #{params.projectRemark},
            </if>
        </set>
        WHERE
        id = #{id}
    </update>


    <insert id="saveProjects" parameterType="com.project.demo.domain.Projects">


        insert into projects
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectName != null">
                name,
            </if>
            <if test="remark != null">
                remark,
            </if>
            <if test="usersId != null">
                users_id,
            </if>
            <if test="startTime != null">
                start_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="projectName != null">
                #{projectName},
            </if>
            <if test="remark != null">
                #{remark},
            </if>
            <if test="usersId != null">
                #{usersId},
            </if>
            <if test="startTime != null">
                #{startTime},
            </if>
        </trim>
    </insert>

    <select id="findByStartTime" resultMap="projectsMap">
        SELECT
        *
        FROM projects
        where start_time = #{startTime}
    </select>


</mapper>