<?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.hchyun.test.dao.ResultsDao">
    
    <resultMap type="Results" id="ResultsResult">
        <result property="id"    column="id"    />
        <result property="sId"    column="s_id"    />
        <result property="java"    column="java"    />
        <result property="images"    column="images"    />
        <result property="file"    column="file"    />
    </resultMap>

    <sql id="selectResultsVo">
        select id, s_id, java, images, file from sys_results
    </sql>

    <select id="selectResultsList" parameterType="Results" resultMap="ResultsResult">
        <include refid="selectResultsVo"/>
        <where>  
            <if test="java != null "> and java = #{java}</if>
        </where>
    </select>
    
    <select id="selectResultsById" parameterType="Long" resultMap="ResultsResult">
        <include refid="selectResultsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertResults" parameterType="Results" useGeneratedKeys="true" keyProperty="id">
        insert into sys_results
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sId != null">s_id,</if>
            <if test="java != null">java,</if>
            <if test="images != null and images != ''">images,</if>
            <if test="file != null and file != ''">file,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sId != null">#{sId},</if>
            <if test="java != null">#{java},</if>
            <if test="images != null and images != ''">#{images},</if>
            <if test="file != null and file != ''">#{file},</if>
         </trim>
    </insert>

    <update id="updateResults" parameterType="Results">
        update sys_results
        <trim prefix="SET" suffixOverrides=",">
            <if test="sId != null">s_id = #{sId},</if>
            <if test="java != null">java = #{java},</if>
            <if test="images != null and images != ''">images = #{images},</if>
            <if test="file != null and file != ''">file = #{file},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteResultsById" parameterType="Long">
        delete from sys_results where id = #{id}
    </delete>

    <delete id="deleteResultsByIds" parameterType="String">
        delete from sys_results where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>