doma2を使用したin句の条件設定
完全一致はあるけど
他の方法ってなかなか見つからないです
IN句による条件指定
select * from keiyaku where name in ('tanaka', 'inoue')
こんなやつ
Dao
KeiyakuDao.java
package com.example.dao; import java.util.List; import org.seasar.doma.Dao; import org.seasar.doma.Select; import com.example.config.AppConfig; import com.example.entity.Keiyaku; import com.example.entity.KeiyakuItem; @Dao(config = AppConfig.class) public interface KeiyakuDao { @Select List<Keiyaku> findNamesSearchAll(List<String> names); }
※引数にList形式で設定する
SQL
findNamesSearchAll.sql
select * from keiyaku where where name in /* names */('aaa', 'bbb', 'ccc')
※inを指定するが別に特別な記載はしない
実行
Sample01.java
package com.example; import java.util.Arrays; import java.util.List; import org.seasar.doma.jdbc.tx.TransactionManager; import com.example.config.AppConfig; import com.example.dao.KeiyakuDao; import com.example.dao.KeiyakuDaoImpl; import com.example.entity.Keiyaku; import com.example.entity.KeiyakuItem; public class Sample01 { public static void main(String[] args) { TransactionManager tm = AppConfig.singleton().getTransactionManager(); tm.required(new Runnable(){ @Override public void run() { KeiyakuDao dao = new KeiyakuDaoImpl(); List<Keiyaku> list; list = dao.findNamesSearchAll(Arrays.asList("tanaka", "inoue")); } }); } }
↓
1 04, 2017 11:35:44 午前 org.seasar.doma.jdbc.tx.LocalTransaction begin 情報: [DOMA2063] ローカルトランザクション[1190654826]を開始しました。 1 04, 2017 11:35:44 午前 com.example.dao.KeiyakuDaoImpl findNamesSearchAll 情報: [DOMA2220] ENTER : クラス=[com.example.dao.KeiyakuDaoImpl], メソッド=[findNamesSearchAll] 1 04, 2017 11:35:44 午前 com.example.dao.KeiyakuDaoImpl findNamesSearchAll 情報: [DOMA2076] SQLログ : SQLファイル=[META-INF/com/example/dao/KeiyakuDao/findNamesSearchAll.sql], select * from keiyaku where name in ('tanaka', 'inoue') 1 04, 2017 11:35:44 午前 com.example.dao.KeiyakuDaoImpl findNamesSearchAll 情報: [DOMA2221] EXIT : クラス=[com.example.dao.KeiyakuDaoImpl], メソッド=[findNamesSearchAll] 1 04, 2017 11:35:44 午前 org.seasar.doma.jdbc.tx.LocalTransaction commit 情報: [DOMA2067] ローカルトランザクション[1190654826]をコミットしました。 1 04, 2017 11:35:44 午前 org.seasar.doma.jdbc.tx.LocalTransaction commit 情報: [DOMA2064] ローカルトランザクション[1190654826]を終了しました。
まあ、こんな感じですかね…