版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38207970/article/details/88391270
案例:
动态sql语句
<select id="queryRAWValue" parameterClass="java.util.HashMap" resultClass="java.util.HashMap" >
<dynamic prepend="select">
<isNotNull prepend="," property="attrName00"> $attrName00$</isNotNull>
<isNotNull prepend="," property="attrName01"> $attrName01$</isNotNull>
<isNotNull prepend="," property="attrName02"> $attrName02$</isNotNull>
<isNotNull prepend="," property="attrName03"> $attrName03$</isNotNull>
</dynamic>
from $TABLENAME$
where 1=1
<isNotNull prepend="and" property="CValue00"> $CAtt00$ $COptional00$ #CValue00#</isNotNull>
<isNotNull prepend="and" property="CValue01"> $CAtt01$ $COptional01$ #CValue01#</isNotNull>
<isNotNull prepend="and" property="CValue02"> $CAtt02$ $COptional02$ #CValue02#</isNotNull>
<isNotNull prepend="and" property="CValue03"> $CAtt03$ $COptional03$ #CValue03#</isNotNull>
<dynamic prepend="and" open="(" close=")">
<isNotNull prepend="or" property="KeyValue00"> $KeyAtt$ = #KeyValue00#</isNotNull>
<isNotNull prepend="or" property="KeyValue01"> $KeyAtt$ = #KeyValue01#</isNotNull>
</dynamic>
</select>
执行sql:
List<Map<String, Object>> retMap = (List<Map<String, Object>>) getSqlExe().queryForList("queryRAWValue", cIMMaps);
当执行一次查询后会自动把sql语句缓存,第二次执行时会把缓存中的sql执行,而不会重新组织sql。所以会出现当第二次传入的cIMMaps值变化时(主要是需要查询的字段),查询出现错误:字段无效。
解决方法:
<select id="queryRAWValue" parameterClass="java.util.HashMap" resultClass="java.util.HashMap" remapResults="true">
在select便签中加入remapResults=“true”,每次查询重组sql。