Mybaits配置文件之动态SQL配置备忘录

时间:2019-03-30
本文章向大家介绍Mybaits配置文件之动态SQL配置备忘录,主要包括Mybaits配置文件之动态SQL配置备忘录使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

动态参数拼接的查询语句

?传入参数类型为自定义数据类型

<select id="queryMessageList" parameterType="com.imooc.bean.Message"
    resultMap="MessageResult">
    select ID,COMMAND,DESCRIPTION,CONTENT from MESSAGE where 1=1
    <if test="command !=null &&!"".equals(command.trim())">
      and COMMAND=#{command}
    </if>
    <if test="description != null and !"".equals(description.trim())">
      and DESCRIPTION like '%' #{description} '%'
    </if>
  </select>

删除单条数据

?传入参数类型为String与基本数据类型

<delete id="deleteOne" parameterType="int">
    delete from MESSAGE WHERE ID = #{_parameter}
</delete>

删除多条数据

?传入参数类型为List

  <delete id="deleteBatch" parameterType="java.util.List">
    delete from MESSAGE WHERE ID in (
    <foreach collection="list" item="item" separator=",">
      #{item}
    </foreach>
    )
  </delete>

以上所述是小编给大家介绍的Mybaits配置文件之动态SQL配置备忘录,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!