<?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.ho.business.mapper.UserHabitMapper">

    <sql id="Base_Column_List">
        id,user_id,user_data
    </sql>

    <insert id="insertUserHabit" parameterType="com.ho.business.entity.UserHabit">
        insert into user_habit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="userData != null">user_data,</if>

        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">  #{userId},</if>
            <if test="userData != null">#{userData},</if>
        </trim>
    </insert>

    <update id="updateById" parameterType="com.ho.business.entity.UserHabit">
        update user_habit
        <set>
            <if test="userData != null">
                user_data = #{userData},
            </if>
        </set>
        where id = #{id}
    </update>

    <select id="selectByUserId" resultType="com.ho.business.entity.UserHabit">
        SELECT <include refid="Base_Column_List"/>
        FROM user_habit
        WHERE user_id = #{userId}
        limit 1
    </select>

</mapper>
