0
多くの条件が 'と'または 'のリストに結合されている検索アプリケーションがあります。Ebeanクエリに式を動的に含めるにはどうすればよいですか?
ユーザーの入力に基づいて、それらの一部はnullになる可能性があります。これらの値は、nullの場合は考慮しないでください。
例:
public static PagedList<Profile> exampleForSO(String param1, String params2, Integer number, Double d, Boolean condition1, Boolean condition2) {
return find.where().ieq("param1", param1).
ieq("param2", params2).
eq("number", number).
// based on the fact if condition1 is null include an eq("condition", condition1); block
// based on the fact if condition2 is null include an eq("condition", condition1); block
// if param1.equals("test") create an expression .eq("param1", param1).
findPagedList();
}
私はおそらく他のブロックならば、いくつかでそれを解決し、その基準に基づいて結果を返すが、12の以上の異なる条件、したがって、ちょうど場合は、それらを除外するために固体の方法がある可能性があり彼らはnullが素晴らしいだろう。
私は多くの異なる方法を作成することもできますが、よりスマートな方法が必要です。
また条件がnullである必要はありませんが、例えば、クエリでそれらを時代遅れになり、いくつかの特定の値、持つことができ:「何か」がないので
params1.equals("something");
がそれを含めないでくださいとにかく検索結果を変更してください。
提案がありますか?
は([ポスト]これを見て持ってhttp://stackoverflow.com/questions/31534272/optional-columns-to-filter-database-records /) – Sivakumar
@Sivakumar、ありがとう、私が探しているものです。 –