mybatis多个查询条件

 

<!--随便下面参数的其中一个都可以查询-->

<!-- <select id="selectBankInfo" resultMap="BaseResultMap" >

SELECT

bankHolderName,bankHolderStatus,bankAccountNum,bankName,branchName,branchAddress

from dms_master d

inner join dms_payment s

on d.accountId=s.accountId

<where>

<if test="keyword!=null and keyword!= ''">

or d.accountId= #{keyword}

</if>

<if test="keyword!=null and keyword!= ''">

or d.name= #{keyword}

</if>

<if test="keyword!=null and keyword!= ''">

or d.IDNum= #{keyword}

</if>

</where>

</select>-->

 

三选一

<select id="selectBankInfo" resultMap="BaseResultMap" >

SELECT

bankHolderName,bankHolderStatus,bankAccountNum,bankName,branchName,branchAddress

from dms_master d

inner join dms_payment s

on d.accountId=s.accountId

<where>

<choose>

<when test="accountid!=null and accountid!= ''">

and d.accountId= #{accountid}

</when>

<when test="name!=null and name!= ''">

and d.name= #{name}

</when>

<when test="idnum!=null and idnum!= ''">

and d.IDNum= #{idnum}

</when>

<otherwise>

and d.accountId= #{accountid}

</otherwise>

</choose>

</where>

</select>

三个都选

<select id="selectBankInfo" resultMap="BaseResultMap" >

SELECT

bankHolderName,bankHolderStatus,bankAccountNum,bankName,branchName,branchAddress

from dms_master d

inner join dms_payment s

on d.accountId=s.accountId

<where>

<iftest="accountid!=null and accountid!= ''">

and d.accountId= #{accountid}

</if>

<iftest="name!=null and name!= ''">

and d.name= #{name}

</if>

<iftest="idnum!=null and idnum!= ''">

and d.IDNum= #{idnum}

</if>

</where>

</select>

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis是一款优秀的ORM框架,它支持多条件查询。实现多条件查询的方式是利用MyBatis的特色——动态SQL。动态SQL允许我们根据不同的条件来动态构建SQL语句,从而实现多条件查询的功能。 总结来说,我们可以使用MyBatis的动态SQL特性来构建多条件查询。通过在MyBatis的核心配置文件中定义查询语句,并使用占位符来设置查询条件,我们可以根据需要动态生成查询语句。例如,在UserMapper.xml文件中,我们可以使用<select>元素来定义多条件查询语句,并使用占位符来设置条件。 在测试代码中,我们可以创建一个封装查询条件的对象QueryVo,并设置相应的属性来指定查询条件。然后,将QueryVo对象作为参数传递给查询方法,即可完成多条件查询。 需要注意的是,我们可以通过设置<select>元素的resultType属性来指定查询结果的输出类型。这样,查询结果将会被映射到指定的类型中,方便我们进行后续的处理。 以上就是使用MyBatis进行多条件查询的基本方法和步骤。通过动态SQL和合适的配置,我们可以根据不同的条件进行灵活的查询操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [java配合MyBatis条件查询及动态SQL](https://download.csdn.net/download/ybb_ymm/87916420)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Mybatis_多条件查询](https://blog.csdn.net/hxy1625309592/article/details/113527256)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值