mybatis 的 delete和update语句

mybatis的delete

<delete id="deleteById">
    delete from sys_user where id = #{id}
delete>
  • 注解@Delete
@Delete({"delete from sys_role where id = #{id}"})

void detele1(Long id);

mybatis的update

<update id="updateById" parameterType="SysUser">
update sys_user
  <set>
   <if test="userName !=null and userName!=''">
    user_name = #{userName},
   if>
   <if test="userPassword !=null and userPassword !=''">
    user_password = #{userPassword},
   if>
   <if test="userEmail !=null and userEmail !=''">
    user_email = #{userEmail},
   if>
   <if test="userInfo !=null and userInfo !=''">
    user_info = #{userInfo},
   if>
   <if test="headImg !=null">
    head_img = #{headImg},
   if>
   <if test="createTime !=null">
    create_time = #{createTime},
   if>
  set>
  <where>
   id = #{id}
  where>
update>
  • 注解@update

@Update({ "update sys_role set role_name=#{roleName},enabled = #{enabled},"
       + "create_by=#{createBy},create_time=#{createTime,jdbcType=TIMESTAMP} " 
       + "where id=#{id}"})
void update1(SysRole sysRole);

你可能感兴趣的:(mybatis)