搬砖中的小事之代码(十)--EasyUI多条件组合查询的实现

EasyUI多条件组合查询实现:
下拉框使用select,添加属性class=”easyui-combobox”,其次设置默认值(也就是什么不选的时候),应该添加一个空的
只需要给option的属性value赋值为空串,写成:value=””
下面是具体的代码实现:

jsp页面代码:

<!-- 定义Grid -->
    <table id="customerdg">
    </table>
<div id="customertb" style="padding:2px 5px;">
        <input id="customerCode" class="easyui-textbox" label="客户编码:" data-options="prompt:'客户编码...'" style="width:15%;">
        <input id="customerNameShort" class="easyui-textbox" label="客户简称:" data-options="prompt:'客户简称...'" style="width:15%;">
        <!-- 1、已立项;2、沟通中;3、已报卷;4、已上线;5、合作中止; -->
        <select id="customerStatus" class="easyui-combobox" style="width:200px;" name="status"  data-options="prompt:'请选择...',
                    label: '客户状态:',
                    labelPosition: 'left'
                    ">
            <!-- 添加默认选项--请选择,为不选择任何一个下拉框子选项 -->
            <option value="">请选择</option>
            <option value="1">已立项</option>
            <option value="2">沟通中</option>
            <option value="3">已报卷</option>
            <option value="4">已上线</option>
            <option value="5">合作中止</option>
        </select>
        <select id="customerChecked" class="easyui-combobox" style="width:200px;" name="checked"  data-options="prompt:'请选择...',
                    label: '审核状态:',
                    labelPosition: 'left'
                    ">
            <!-- 添加默认选项--请选择,为不选择任何一个下拉框子选项 -->
            <option value="">请选择</option>
            <option value="1">未审核</option>
            <option value="2">审核中</option>
            <option value="3">审核成功</option>
            <option value="4">审核失败</option>
        </select>
        <a id="customersearch" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a>     
    </div>

对应的js获取字段的值写法:

//查询(四个搜索条件:客户编码+客户简称+客户状态+审核状态)
    $('#customersearch').bind("click", function(){
            var obj = {
                    "code": $("#customerCode").val()||undefined,
                    "status": $("#customerStatus").val()||undefined,
                    "checked": $("#customerChecked").val()||undefined,
                    "nameShort": $("#customerNameShort").val()||undefined

            };
            $('#customerdg').datagrid('load',  obj );
        });

其次在dao.xml的查询配置,注意加上每个字段的非空判断和trim()去除空格的判断:
部分代码实例:

<select id="queryList" resultMap="BaseResultMap">
        select * from crm_customer
        <where>
            deleted=0
            <if test="code != null and code.trim() !=''" >
                and code = #{code}
            </if>
            <if test="name != null and name.trim() !=''">
                and name = #{name}
            </if>
            <if test="nameShort != null and nameShort.trim() !=''">
                and name_short like CONCAT(CONCAT('%', #{nameShort}), '%')
            </if>
            <if test="status != null and status.trim() !=''">
                and status = #{status}
            </if>
            <if test="checked != null and checked.trim() !=''">
                and checked = #{checked}
            </if>
        </where>
        <if test="order != null and sort != null ">
            order by ${sort} ${order}
        </if>
        <if test="offset != null and limit != null ">
            limit #{offset}, #{limit}
        </if>
    </select>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值