当sql配置文件中的元素select/insert/update中,需要使用大于号>和小于号<时。
<![CDATA[
sql语句
]]>
来将sql语句括起来,如:
<select id="test_query" parameterType="hashmap" resultType="hashmap">
<![CDATA[
select t.f1,t.f2
from table t
where t.f3 <> 1
]]>
<include refid="test_sql_common" />
</select>
或者通过以下方式:
<select id="findUserByCond" parameterClass="java.util.Map" resultMap="userMapping">
SELECT
*
FROM
lol_user
where
1=1
<isNotEmpty prepend=" AND " property="userName">
user_name like '%$userName$%'
</isNotEmpty>
<isNotEmpty prepend=" AND " property="realName">
real_name like '%$realName$%'
</isNotEmpty>
<isNotEmpty prepend=" AND " property="startTime"> create_time >= #startTime# </isNotEmpty>
<isNotEmpty prepend=" AND " property="endTime"> create_time <= #endTime#</isNotEmpty>
order by create_time desc
limit #offset#,#pageSize#
</select>