MyBatis-动态SQL
1. 模糊查询
#{value} 以?的方式传参到数据库 ‘value’
${id} 以拼接的方式传参到数据库 value
示例
<!-- 模糊查询 -->
<select id="selectList" resultMap="BaseResultMap">
select * from book where book_name like '%${bookName}%'
</select>
2. where
<!-- 多条件查询 -->
示例
<!-- 多条件查询 -->
<select id="selectCondition" resultMap="BaseResultMap">
select * from book
<where>
<if test="bookName !=null and bookName != ''">
book_name = #{bookName}
</if>
<if test="bookAuth !=null and bookAuth != ''">
and book_auth = #{bookAuth}
</if>
<if test="bookBrief !=null and bookBrief != ''">
and book_brief like '%${bookBrief}%'
</if>
</where>
</select>