0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【忘備録】iBatis2

Last updated at Posted at 2016-06-18

iBatis2に関するメモ書きです。

iBatis2の日本語マニュアル

removeFirstPrepend

初めの入れ子のタグが生成するタグのprependを削除する

例えばnameまたはvalueで絞り込みたいため、下記のSQLを記述したとします。

WHERE
 <isNotEmpty property="name" prepend="AND">
    name = #name#
 </isNotEmpty>
 <isNotEmpty property="value" prepend="AND">
    value = #value#
 </isNotEmpty>

nameかvalueのどちらかは必ずNotEmptyになるので、WHERE句をdinamicタグを使わずに記述しています。

nameがNotEmpty、valueがEmptyのとき、WHERE AND name=#name#が出力され、SQL構文エラーになります。
この場合removeFirstPrepend="true"を付与すれば、最初の要素にはANDが付かず、正しいSQL文が出力されます。

WHERE
 <isNotEmpty property="name" prepend="AND" removeFirstPrepend="true">
    name = #name#
 </isNotEmpty>
 <isNotEmpty property="value" prepend="AND" removeFirstPrepend="true">
    value = #value#
 </isNotEmpty>

#, $のエスケープ

##, $$と2回連続で記述します。

http://www.canetrash.jp/article/2451052.html 参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?