请教ibatis中多条件查询!

czp3158 2009-05-20 10:17:44

<!-- -->
<select id="selectAllAgentbooksbypage" resultClass="Agentbooks" parameterClass="java.util.Map">
select * from Agentbooks
<dynamic prepend="WHERE">
<isParameterPresent>
<isEqual prepend="AND" property="addtime" >
addtime between #stime# and #etime#
</isEqual>
</isParameterPresent>
<isNotEmpty prepend="AND" property="agprovince">
agprovince=#agprovince#
</isNotEmpty>
<isNotEmpty prepend="AND" property="agcity" >
agcity=#agcity#
</isNotEmpty>
<isNotEmpty prepend="AND" property="probigtype">
probigtype=#probigtype#
</isNotEmpty>
<isNotEmpty prepend="AND" property="proname">
(proname like '%$proname$%')
</isNotEmpty>
order by addtime desc limit #index#,#pagesize#
</dynamic>
</select>

在配置:

<isParameterPresent>
<isEqual prepend="AND" property="addtime" >
addtime between #stime# and #etime#
</isEqual>
</isParameterPresent>
时出了问题!
请问各位高手该如何更改?
...全文
194 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
NickCheng 2009-05-20
  • 打赏
  • 举报
回复
应该这样可以:

<select id="selectMyAgentbooksbypage" resultClass="Agentbooks" parameterClass="java.util.Map">
select * from Agentbooks
<dynamic prepend="WHERE">
<isNotEmpty prepend="AND" property="stime">
addtime >= #stime#
</isNotEmpty >
<isNotEmpty prepend="AND" property="etime">
<![CDATA[
addtime < #etime#
]]>
</isNotEmpty >
<isNotNull prepend="AND">
stat = 1
</isNotNull >
<isNotNull prepend="AND">
auditing=0
</isNotNull >
<isNotEmpty prepend="AND" property="userid">
userid = #userid#
</isNotEmpty >
</dynamic>
order by #orderby# #rule# limit #index#,#pagesize#
</select>


吐司vivi 2009-05-20
  • 打赏
  • 举报
回复
顶一下
a1123454 2009-05-20
  • 打赏
  • 举报
回复
<select id="getPageRecord" parameterClass="RequestMapping"
resultClass="ResultMapping">
<![CDATA[
select
a.ai_id,
a.ai_code,
a.ai_name,
a.ai_price,
a.ai_amount,
a.ai_unit,
a.ai_usamount,
a.ai_isbuy,
a.ai_remark ,
a.ac_id,
b.ac_name
from bs_assets_info a
inner join bs_assets_category b on b.ac_id=a.ac_id


]]>
<dynamic prepend="where">
<isNotEmpty prepend="and" property="ai_name">
<![CDATA[ a.ai_name like concat('%',#ai_name#,'%')]]>
</isNotEmpty>
<isNotEmpty prepend="and" property="ai_code">
<![CDATA[ a.ai_code = #ai_code# ]]>
</isNotEmpty>
<isNotEmpty prepend="and" property="ac_id">
<![CDATA[ a.ac_id = #ac_id#]]>
</isNotEmpty>
</dynamic>
<dynamic prepend="order by">
<isNotEmpty property="fieldOrder">
<![CDATA[ $fieldOrder$ ]]></isNotEmpty>
</dynamic>
<![CDATA[ $foot$ ]]>
</select>

我看到的一个动态查询例子
  • 打赏
  • 举报
回复
property="addtime"要和#之间的占位符对应
2个参数需要定义一个参数类
建议between改为>=和<

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧