修改rbac bug遇到的一个问题
以下是按照or条件进行查询的语句:
<select id="getAccountListbyDTOor" resultClass="cc.c37c.rbac.common.vo.RbacUserDTO">
SELECT ACCOUNTROWID AS accountrowid
......
FROM RBAC_USER a WHERE deleted != '1'
<isNotNull prepend=" or" property="accountid">
a.ACCOUNTID = #accountid#
</isNotNull>
<isNotNull prepend=" or" property="creator">
<![CDATA[ CREATOR = #creator#]]>
</isNotNull>
.....
</select>
SELECT ACCOUNTROWID AS accountrowid
......
FROM RBAC_USER a WHERE deleted != '1'
<isNotNull prepend=" or" property="accountid">
a.ACCOUNTID = #accountid#
</isNotNull>
<isNotNull prepend=" or" property="creator">
<![CDATA[ CREATOR = #creator#]]>
</isNotNull>
.....
</select>
where后面加了一个deleted != '1' 之后拼接的 or ,此时无论其中or条件值是否正确,搜索的结果都是deleted != '1'时的结果集
业务的要求应该是下面的形式:
select * from table where xxx = "xxx" and (xxx1="xxx" or xx2="xx1")
改为下面的形式即可:
<select id="getAccountListbyDTOor" resultClass="cc.c37c.rbac.common.vo.RbacUserDTO">
SELECT ACCOUNTROWID AS accountrowid
......
FROM RBAC_USER a WHERE deleted != '1'
<dynamic prepend=" and" open="(" close=")">
<isNotNull prepend=" or" property="accountid">
a.ACCOUNTID = #accountid#
</isNotNull>
<isNotNull prepend=" or" property="creator">
<![CDATA[ CREATOR = #creator#]]>
</isNotNull>
.....
</dynamic>
</select>
SELECT ACCOUNTROWID AS accountrowid
......
FROM RBAC_USER a WHERE deleted != '1'
<dynamic prepend=" and" open="(" close=")">
<isNotNull prepend=" or" property="accountid">
a.ACCOUNTID = #accountid#
</isNotNull>
<isNotNull prepend=" or" property="creator">
<![CDATA[ CREATOR = #creator#]]>
</isNotNull>
.....
</dynamic>
</select>