sql1
sql2
没经过测试,一般动态ibatis SQL动态语句是用来动态改变一条SQL语句的条件(包括where 条件和 select 的字段条件)
一般不会你说的那么用,因为你这个问题,完全可以在xml写两个ibatis statement,在java里判断A,B是否为空,来决定调一个还是两个statement
C#是这么写的,ibatis2不了解,但是看到isNotEmpty
string Condition = " where 1=1 ";
if (!string.IsNullOrEmpty(KeyWord))
{
Condition += " and aa like '%" + KeyWord.Replace("'", "''") + "%' ";
}
if (!string.IsNullOrEmpty(Remark))
{
Condition += " and Remark = '" + Remark.Replace("'", "''") + "' ";
}
string SelectString = "select * from table " + Condition + " order by Date desc";