mybatis的mapper文件增、删、改、查

╰半橙微兮° 2021-07-26 15:52 368阅读 0赞

查询

  1. <select id="findActiveBlogWithTitleLike" resultType="Blog">
  2. SELECT * FROM BLOG
  3. WHERE state = ‘ACTIVE’
  4. <if test="title != null">
  5. AND title like #{title}
  6. </if>
  7. </select>

增加

  1. <insert id="insertAuthor" useGeneratedKeys="true"
  2. keyProperty="id">
  3. insert into Author (username,password,email,bio)
  4. values (#{username},#{password},#{email},#{bio})
  5. </insert>

删除

  1. <delete id="deleteAuthor">
  2. delete from Author where id = #{id}
  3. </delete>

修改

  1. <update id="updateAuthorIfNecessary">
  2. update Author
  3. <set>
  4. <if test="username != null">username=#{username},</if>
  5. <if test="password != null">password=#{password},</if>
  6. <if test="email != null">email=#{email},</if>
  7. <if test="bio != null">bio=#{bio}</if>
  8. </set>
  9. where id=#{id}
  10. </update>

发表评论

表情:
评论列表 (有 0 条评论,368人围观)

还没有评论,来说两句吧...

相关阅读