Skip to content
快捷导航

MyBatis 底层操作数据库配置文件两种传参数方式

1. 实体类参数方式

xml
<update id="updateByPrimaryKeySelective" parameterType="com.jw.admin.entity.sys.SysUserRole" >
  update jw_sys_user_role
  <set >
    <if test="userId != null" >
      user_id = #{userId,jdbcType=BIGINT},
    </if>
    <if test="roleId != null" >
      role_id = #{roleId,jdbcType=BIGINT},
    </if>
    <if test="createTime != null" >
      create_time = #{createTime,jdbcType=TIMESTAMP},
    </if>
    <if test="updateTime != null" >
      update_time = #{updateTime,jdbcType=TIMESTAMP},
    </if>
  </set>
  where id = #{id,jdbcType=BIGINT}
</update>

2. json参数方式

xml
<update id="updateArticle" parameterType="com.alibaba.fastjson.JSONObject">
  UPDATE jw_crm_article
  SET
    content = #{content},
    title = #{title},
    public_time = #{publicTime}
  WHERE id = #{id}
</update>