小程序sql

<insert id="insert" parameterType="HashMap">
	INSERT INTO tb_user
    SET
    <if test="openId!=null">
    	open_id = #{openId},
    </if>
    <if test="nickname!=null">
    	nickname = #{nickname},
    </if>
    <if test="photo!=null">
    	photo = #{photo},
    </if>
    <if test="name!=null">
        name = #{name},
    </if>
    <if test="sex!=null">
        sex = #{sex},
    </if>
    <if test="tel!=null">
        tel = #{tel},
    </if>
    <if test="email!=null">
        email=#{email},
    </if>
    <if test="hiredate!=null">
        hiredate = #{hiredate},
    </if>
    role = #{role},
    root = #{root},
    <if test="deptName!=null">
        dept_id = ( SELECT id FROM tb_dept WHERE dept_name = #{deptName} ),
    </if>
    status = #{status},
    create_time = #{createTime}
</insert>

  参数类型是HashMap

 

<select id="getIdByOpenId" parameterType="String" resultType="Integer">
        select id from tb_user where open_id = #{openId}
    </select>

  查询id返回Integer,因为Interger结果不存在时可以返回null

posted @ 2023-10-11 22:42  sgj191024  阅读(22)  评论(0编辑  收藏  举报