IBatis动态查询帮助
我有一个名为“用户”的表,其中包含以下列 userid,name,gender,department,managerid...
我想做这个查询,但有 2 个问题
1.《》第 4 行引起了问题,这是由于 XML 造成的。我需要使用,但即使经过一些排列后也无法让事情顺利进行。
2. 只有当传递的地图包含部门时才需要检查部门='工程'。所以这需要是动态的。
有人可以写下我如何在 Ibatis 中完成这项工作吗?感谢您的帮助 !!!
select * from users
where userid=#userid#
and gender = 'm'
and (managerid ISNULL OR managerid <> #mgrid#)
and department = 'engineering'
我尝试过,但没有成功....有什么帮助吗?
<select id="getEmployees" parameterClass="java.util.HashMap" resultMap="empResultMap">
<![CDATA[
select * from users
where userid=#userid#
and gender = 'm'
and (managerid ISNULL OR managerid <> #mgrid#)
<dynamic>
<isNotEmpty property="mgrid">
( AND department = #mgrid# )
</isNotEmpty>
</dynamic>
]]>
</select>
I have a table called "users" with following columns
userid,name,gender,department,managerid....
I wanted to do this query but was having 2 issues
1. <> in line 4 is is causing problem, which is due to to the XML. I need to use but was not able to get things going even after some permutations.
2. the check department = 'engineering' needs to be done only if the map passed contains department. so this needs to be dynamic.
Can some one scribble as to how I could get this done in Ibatis. thanks for your help !!!
select * from users
where userid=#userid#
and gender = 'm'
and (managerid ISNULL OR managerid <> #mgrid#)
and department = 'engineering'
I tried this but did not work ....any help??
<select id="getEmployees" parameterClass="java.util.HashMap" resultMap="empResultMap">
<![CDATA[
select * from users
where userid=#userid#
and gender = 'm'
and (managerid ISNULL OR managerid <> #mgrid#)
<dynamic>
<isNotEmpty property="mgrid">
( AND department = #mgrid# )
</isNotEmpty>
</dynamic>
]]>
</select>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会这样尝试:
请注意从“ISNULL”到“IS NULL”的语法更正。祝你好运!
I would try it like this:
Please note the syntax correction from "ISNULL" to "IS NULL". Good luck!
感谢科里的快速回复。您的建议非常有效。
进一步补充同一问题,如果我想在动态标记中有多个 AND/OR,格式应该是什么?
我尝试了这个,但它不起作用(特别是当 mgrid =“” 时)
再次感谢您的回复。
Thanks Cory for the quick reply. Your suggestion did work great.
Adding further to the same question, if I want to have multiple AND/OR in the dynamic tag, what should be the format?
I tried this but it did not work (especially when mgrid = "")
Once again thanks for the response.