20、mybatis学习——<bind>绑定

      <select id="getStuByTrim" resultType="student">
         select * from student
         <!-- 绑定参数拼接字符串 -->
         <bind name="stuName" value="'%'+name+'%'"/>
         <trim prefix="where" prefixOverrides="and"  >
             <if test="id!=null">
                 id = #{id}
             </if>
             <if test="name!=null &amp;&amp; name.trim()!=''">
                 and name like #{stuName}
             </if>
         </trim>
     </select>

这样我们在查询时,name属性可以不用自带%号

自动拼接了%

 

原文地址:https://www.cnblogs.com/lyh233/p/12362667.html