easyui之combobox快速搜索

第一次用combobox的快速搜索功能,很多人会因为不懂关键词q,而不知所措,q到底是什么鬼?q其实代表的是combobox的输入的内容。下面是具体的实现的效果如下图:

1.前端实现代码如下:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="../js/easyui-1.5.1/jquery.min.js"></script>
        <script src="../js/easyui-1.5.1/jquery.easyui.min.js"></script>
        <script src="../js/easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
        <link href="../js/easyui-1.5.1/themes/black/easyui.css" rel="stylesheet" />
        <link href="../js/easyui-1.5.1/themes/icon.css" rel="stylesheet" />
        <style>
            body{
                background: black;
            }
            .search_box{
                text-align: center;
            }
            .search_box input{
                width: 300px;
            }
            
            .result_box{
                width: 600px;
                margin: 20px auto;
            }
            
        </style>
        
        
    </head>
    <body>
        <div class="search_box"><input id="hospitalsearch" name="dept" ></div>
        <div class="result_box"><table id="result_grid"></table> </div>
    </body>
    <script>
        $('#hospitalsearch').combobox({
            url:'http://192.168.0.102:8082/springmvc2/hello/searchByKey.do',
            queryParams: {
                "q" : ''
            },
            valueField:'id',    
            textField:'hospitalName',
            method : "post",
            mode : 'remote',
            onLoadSuccess:function(data){
                $('#result_grid').datagrid('loadData', data);  
            }
        });   

        $('#result_grid').datagrid({ 
            fitColumns:true,//宽度自适应
            width: 600,
            height: 280,
            columns:[[    
                {field:'hosptialGrade',title:'医院等级',width:150},    
                {field:'hospitalName',title:'医院名称',width:150}   
            ]]    
        });  
        
    </script>
</html>

2.后端代码如下:

@ResponseBody
    @RequestMapping("/searchByKey")
    public List<Map<String, Object>> searchByKey(@RequestParam Map<String, Object> params, HttpServletResponse resp,
            HttpServletRequest req) {
        resp.setHeader("Access-Control-Allow-Origin", "*");
        List<Map<String, Object>> list=null;
        try{
         list=comboGridService.searchByKey(params);
        }catch(Exception e){
            e.printStackTrace();
        }
        return  list;
    }

3.数据库sql语句

 <select id="queryHostpitals" resultType="java.util.HashMap" >      
        select * from hospital where  hospital_name like concat('%',#{q},'%')
 </select> 


    

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值