ProjectsMapper.xml 1.75 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="state" property="state" />
        <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>


</mapper>