<select id="selectAllProducts" parameterClass="Product" resultMap="ProductResult"> select id,note from Product <dynamic prepend="WHERE"> <!-- isNotNull判断参数是否存在,Integer类型 --> <isNotNull property="id"> <!-- isGreaterThan判断参数是否大于compareValue,isGreaterEquals是大于等于 --> <isGreaterThan prepend=" and " property="id" compareValue="0"> id = #id# </isGreaterThan> </isNotNull> <!-- isNotEmpty判断字串不为空,isEmpty可以判断字串为空 --> <isNotEmpty prepend=" and " property="note"> <!-- 模糊查询不能用#,#在是用prepareStatement的?插入参数,$是文本替换 --> note like '%$note$%' </isNotEmpty> </dynamic> </select> <!-- 用Map传参数 --> <select id="selectAllHashMap" parameterClass="HashMap" resultMap="ResultMap"> select id,note from hashmap </select> <!-- 动态SQL的参数有 属性关键字 含义--> <isEqual></isEqual> <!--如果参数相等于值则查询条件有效。--> <isNotEqual></isNotEqual> <!--如果参数不等于值则查询条件有效。--> <isGreaterThan></isGreaterThan> <!--如果参数大于值则查询条件有效。--> <isGreaterEqual></isGreaterEqual> <!--如果参数等于值则查询条件有效。--> <isLessEqual></isLessEqual> <!--如果参数小于值则查询条件有效。如下所示:--> <isLessEqual prepend = "AND" property = "age" compareValue = "18" > ADOLESCENT = ‘TRUE’ </isLessEqual> <isPropertyAvailable/> <!--如果参数有使用则查询条件有效。 --> <isNotPropertyAvailable/> <!--如果参数没有使用则查询条件有效。--> <isNull/> <!--如果参数为NULL则查询条件有效。--> <isNotNull/> <!--如果参数不为NULL则查询条件有效。--> <isEmpty/> <!--如果参数为空则查询条件有效。--> <isNotEmpty/> <!--如果参数不为空则查询条件有效。参数的数据类型为Collection、String 时参数不为NULL或“”。如下所示:--> <isNotEmpty prepend="AND" property="firstName" > FIRST_NAME=#firstName# </isNotEmpty> <isParameterPresent/> <!--如果参数类不为NULL则查询条件有效。--> <isNotParameterPresent> Checks to see if the parameter object is not present (null). Example Usage: <isNotParameterPresent prepend="AND"> EMPLOYEE_TYPE = ‘DEFAULT’ </isNotParameterPresent>