java 按条件查询

               按条件查询

     按条件查询分为几个步骤:

       1.从页面上获取查询条件
       2.将查询条件传到后台相应的方法中去
       3.将这些查询条件全部放在一个map中
       4.写sql语句进行查询并把结果返回给前端页面上去展示


比较关键的就是sql语句的书写,将所有的条件都列出,如果为空则不要,不为空在带入查询,举例:

  <select id = "findOrdersByCon" parameterType="java.util.Map" resultType="com.chemguan.entity.Order">
SELECT * FROM `order` where 1=1
<if test="orderNumber != null">  
        and orderNumber = #{orderNumber}  
        </if> 
        <if test="columnName != null">  
        and columnName = #{columnName} 
        </if>
        <if test="productName != null">  
        and productName = #{productName} 
        </if>
        <if test="customerNumber != null">  
        and customerNumber = #{customerNumber} 
        </if>
        <if test="mid != null">  
        and mid = #{mid} 
        </if>
        <if test="storeName != null">  
        and storeName = #{storeName} 
        </if>
        <if test="date1 != null">  
        and createTime &gt;=#{date1} 
        </if>
        <if test="date2 != null">  
        and createTime &lt;=#{date2} 
        </if>
</select>

可以通过ajax方式,也可以通过form表单形式,看情况而定,通过ajax的话要拼接字符串,用form的话则要将获取的查询条件返回到页面上进行显示。反正都可以实现按条件查询的需求,看自己的喜好来!!!


 
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值