成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? Java框架SSH結合Easyui控件實現省市縣三級聯動示例解析
全站頭部文字 我要出現在這里
Java框架SSH結合Easyui控件實現省市縣三級聯動示例解析 751 2024-02-28   

Easyui調用數據庫實現省市縣區三級聯動的效果如果下

查看圖片

查看圖片

查看圖片

1、首先要設計數據庫,如圖所示。一個有4個字段code,note,pycode。code:行政區劃代碼,note:中文注釋,pycode:拼音縮寫。 其中code是由6個字段組成。如果是省級最后4位是0000,如果是地級市最后2位是00,其他是縣區。

我已經把相關數據庫代碼上傳到我的csdn資源中,需要的同學自行下載。

查看圖片

2、我用的是java、SSH框架結合Easyui控件

3、html代碼如下

     <tr>                               
       <td class="left">省:</td>  
       <td><input name="contact.province" id="province" style="width: 174px;" ></td>     
       <td class="left">市:</td>          
       <td><input  name="contact.city" id="city" style="width: 174px;"></td>                       
       <td class="left">縣區:</td>  
       <td><input name="contact.county" id="county" style="width: 174px;" ></td>
    </tr>

4、對應的JS代碼如下

$(function(){
 
 // 下拉框選擇控件,下拉框的內容是動態查詢數據庫信息
 $('#province').combobox({ 
    url:'apply/provinceCombobox_combobox.action',
    editable:false, //不可編輯狀態
    cache: false,
   // panelHeight: 'auto',//自動高度適合
    valueField:'code',  
    textField:'note',
    
 onHidePanel: function(){

   $("#city").combobox("setValue",'');
   $("#county").combobox("setValue",'');
   $("#cregicounty").val('');
  var province = $('#province').combobox('getValue'); 
  if(province!=''){
  $.ajax({
  type: "POST",
  url: "apply/cityCombobox_combobox.action?province="+province,
  cache: false,
  dataType : "json",
  success: function(data){
  $("#city").combobox("loadData",data);
                 }
                }); 
              }
           } 
         }); 
 
 $('#city').combobox({ 

   editable:false, //不可編輯狀態
   cache: false,
   //panelHeight: 'auto',//自動高度適合
   valueField:'code',  
   textField:'note',
   onHidePanel: function(){
   $("#cregicounty").val('');
   $("#county").combobox("setValue",'');
  var city = $('#city').combobox('getValue'); 
  if(city!=''){
  $.ajax({
  type: "POST",
  url: "apply/countyCombobox_combobox.action?city="+city,
  cache: false,
  dataType : "json",
  success: function(data){
  $("#county").combobox("loadData",data);
                 }
                }); 
              }
           }
  }); 
 $('#county').combobox({ 
   editable:false, //不可編輯狀態
   cache: false,
  // panelHeight: 'auto',//自動高度適合
   valueField:'code',  
   textField:'note',
   onHidePanel: function(){
     var str=$('#county').combobox('getText');
   $("#cregicounty").val(str); 
           }
 }); 
 
  $('#country').combobox({//國家代碼初始化 
 valueField:'english',  
   textField:'note',
   url:'json/country.json',
   cache: false,
  //panelHeight: 'auto',//自動高度適合
   onChange: function(newValue,oldValue){ 

   countrySearch(newValue);
   countrys(newValue);
   }
 });
}); 

5、Java的Action代碼

//查詢全國行政區代碼省
 public String provinceCombobox() throws Exception{
 
 List list=comboboxService.findProvince();
 this.jsonUtil(list);
 return null;
 }
 
 //查詢全國行政區代碼市
 public String cityCombobox() throws Exception{
  
 List list=comboboxService.findCity(province);
 this.jsonUtil(list);
   return null;
 }
 
 //查詢全國行政區代碼縣區
 public String countyCombobox() throws Exception{
 
 List list=comboboxService.findCounty(city);
 this.jsonUtil(list);
   return null;
 }
 
 
 //調用json工具方法,傳入參數alist
 public void jsonUtil(Object accountlist) throws Exception{
  HttpServletResponse response = ServletActionContext.getResponse(); 
  log.info("JSON格式:" + accountlist.toString());
  
  String returnJson = JsonConvert.returnJson(accountlist);
  response.setCharacterEncoding("utf-8");
  response.getWriter().println(returnJson);
 }

6、工具JSON代碼

import java.io.StringWriter;

import org.codehaus.jackson.map.ObjectMapper;

public class JsonConvert {
 static String jsonStr;
 public static String returnJson(Object object) throws Exception{
 ObjectMapper objectMapper = new ObjectMapper();
 StringWriter stringWriter = new StringWriter();
 objectMapper.writeValue(stringWriter, object);
 
 jsonStr = stringWriter.toString();
 return jsonStr;
 }
}

7、對應接口代碼

//查詢省
public List findProvince() throws Exception;
//查詢市
public List findCity(String code) throws Exception;
//查詢縣區
public List findCounty(String code) throws Exception;

8、對應接口實現類代碼

 //下拉框--查詢省
 public List findProvince() {
 log.info("===下拉框--查詢省");

 Criteria criteria=this.sessionFactory.getCurrentSession().createCriteria(CareacodeTblQg.class);
 criteria.add(Restrictions.like("code", "%0000"));
 criteria.addOrder(Order.asc("code"));
 
 return criteria.list();
 }
 
 //下拉框--查詢市
 public List findCity(String code2) {
 log.info("===下拉框--查詢市");
 String id=code2.substring(0,2);

 Criteria criteria=this.sessionFactory.getCurrentSession().createCriteria(CareacodeTblQg.class);
 criteria.add(Restrictions.like("code", id+"%00"));
 criteria.add(Restrictions.ne("code",code2 ));
 criteria.addOrder(Order.asc("code"));
 
 return criteria.list();
 }
 
 //下拉框--查詢縣區
 public List findCounty(String code3) {
 log.info("===下拉框--查詢縣區");

 String id=code3.substring(0,4);
 Criteria criteria=this.sessionFactory.getCurrentSession().createCriteria(CareacodeTblQg.class); 
 
 criteria.add(Restrictions.like("code", id+"%"));
 criteria.add(Restrictions.not(Restrictions.like("code", "%01")));
 criteria.add(Restrictions.ne("code",code3 ));
 criteria.addOrder(Order.asc("code"));
 
 return criteria.list();
 }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持綠夏網。



主站蜘蛛池模板: 我家三爷超宠的短剧全集| 林佑星| 搜狐搜狐| av电影在线| 潜龙轰天 电影| 天下免费大全正版资料| 手心里的温柔女声版| 美式壁纸| 黄鸟电影| 新相亲大会第三季 2020| 《西湖的绿》宗璞| 王宝强最新电影叫什么| 雾里看花电视剧| 恋人电影| 泪桥简谱| 寡妇激情毛片免费视频| 我的电影生涯导演| 请赐我一双翅膀在线观看| 现代企业管理| 贵阳三中| 红楼梦小戏骨| 太医派的开胃汤配方| 视频精品| xxoo电影| 国产伦理女村支书| 手绢舞蹈视频大全| free hd xxxx moms movie777| cctv5+体育节目表| 李洋简介| 欠条怎么写才有法律效果| 四 电影| 拿什么拯救你我的爱人剧情简介| 日记100字简单| 金珠和陈诗雅主演的韩剧| 装饰色彩| 吉他谱子| 士兵突击演员| 拿什么拯救你我的爱人演员表介绍| 流萤美图| 玉林电视台| 打男生军人光屁股的网站视频|

?。?!站長長期在線接?。?!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103