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

来源:互联网 发布:intent的传递数据 编辑:程序博客网 时间:2024/05/17 18:27

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 0
原创粉丝点击