Using Like statement in MyBatis 如何在MyBatis使用Like 條件


Using Like statement in MyBatis
如何在MyBatis使用Like 條件

Using like statement in MyBatis does not make the parameter appended with %. The easiest way to make it work, is to use concatenate operator directly in the statement, e.g. + in SQL Server, or || in Oracle.

當要在MyBatis 內使用SQL的Like條件時, %符是不會自動加到參數中的.除了在程式中加入%再傳入參數, 其中一個方法是在SQL 的定義中把%用連接符連在一起, 如SQL SERVER 的+ 或ORACLE 的||.

SQL Server:
<select id="sampleSelectStatment" resultmap="BaseResultMap">
  select a,b,c from tablea where a like '%'+#{param}+'%'
</select>

SQL Server:
<select id="sampleSelectStatment" resultmap="BaseResultMap">
  select a,b,c from tablea where a like '%'||#{param}||'%'
</select>

Comments

Popular Posts