对261个国家地区快速查找选择

实现的效果如下

当输入小写字母“z”的时候,刷出所有以z开头的国家

当输入汉字“美”的时候,刷出以美字开头的国家

1、使用java,SSH,Easyui

2、数据库设计,code:国家英语简写,note:中文注释,pycode:中文拼音缩写,english:英文名称

其中pycode全部为小写,note为中文名称,其余字段全部是大写

3、html代码

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <tr>                      
  2.    <td class="left"><!-- Country -->国籍:</td>                      
  3.    <td clas="right"><input name="passport.country"  id="country" ata-options="valueField: 'CHN',textField: '中国'" class="easyui-validatebox" required="true" style=" 174px;"/>                                
  4.    </td>  
  5. </tr>  


4、js代码

[javascript] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. $(function(){  
  2.      
  3.    $('#country').combobox({//国家代码初始化   
  4.         valueField:'english',     
  5.         textField:'note',  
  6.         url:'json/country.json',  
  7.         cache: false,  
  8.        //panelHeight: 'auto',//自动高度适合  
  9.         onChange: function(newValue,oldValue){    
  10.   
  11.             countrySearch(newValue);  
  12.         }  
  13.     });  
  14. });   
[javascript] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. function countrySearch(newValue){//国家信息更改  
  2.     //判断汉字 (/[u4e00-u9fa5]+/).test(newValue))  
  3.     
  4.     if((/[a-z]+/).test(newValue)||(/[u4e00-u9fa5]+/).test(newValue)){  
  5.         $('#country').combobox({//国家代码初始化   
  6.             valueField:'english',     
  7.             textField:'note',  
  8.             url:'apply/countryCombobox_combobox.action?values='+encodeURI(encodeURI(newValue)),  
  9.             cache: false  
  10.            // panelHeight: 'auto'//自动高度适合  
  11.         });   
  12.     }  
  13.       
  14. }  

5、Action代码

[java] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. //模糊查询国家代码表  
  2. public String countryCombobox() throws Exception{  
  3.     log.info("=====下拉框查询国家代码========");  
  4.     values=URLDecoder.decode(values,"UTF-8");  
  5.     String fields;  
  6.   
  7.     if(values.getBytes().length==values.length()){//如果相等 输入的就不是汉字  
  8.         log.info("pycode");  
  9.         fields="pycode";  
  10.           
  11.     }else{//如果不相等 输入的就是汉字  
  12.         log.info("note");  
  13.         fields="note";  
  14.                   
  15.     }  
  16.           
  17.     List list=comboboxService.findCountry(fields, values);  
  18.       
  19.     this.jsonUtil(list);  
  20.     return null;  
  21. }  


6、接口

[java] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. //查询国家代码表  
  2. public List findCountry(String fileds,String values) throws Exception;  


7、接口实现类

[java] view plaincopy在CODE上查看代码片派生到我的代码片
 
    1. //查询国家代码表  
    2. public List findCountry(String fields,String values) throws Exception{  
    3.     Criteria criteria=this.sessionFactory.getCurrentSession().createCriteria(CcountryTbl.class);  
    4.       
    5.     //当属性和值都不为空的时候,进行模糊查询  
    6.     if(StringUtils.isNotBlank(fields)&&StringUtils.isNotBlank(values)){  
    7.         criteria.add(Restrictions.like(fields, values+"%"));  
    8.     }  
    9.       
    10.     return criteria.list();  
    11. }  
原文地址:https://www.cnblogs.com/henuyuxiang/p/4283010.html