EasyUIはデータベースを呼び出して、州、都市、郡、地区間の3レベルのリンクの効果を実現します。
1.最初に、図に示すようにデータベースを設計します。 1つは4つのフィールドコード、ノート、Pycodeを持っています。コード:管理部コード、注:中国の注釈、Pycode:Pinyin略語。コードは6つのフィールドで構成されています。それが地方レベルの場合、それは0,000であり、それが県レベルの都市である場合、それは00であり、もう1つは郡と地区です。
関連するデータベースコードをCSDNリソースにアップロードしましたが、それを必要とする学生は自分でダウンロードします。
2。easyUIコントロールと組み合わせたJava、SSHフレームワークを使用します
3. HTMLコードは次のとおりです
<tr> <td>州:</td> <td> <input name = "contact.province" id = "province"> </td> <td> city:</td> <td> <input name = "contact.city" id = "city"> </td> <td> </tr>
4.対応するJSコードは次のとおりです
$(function(){//ドロップダウンボックスのコントロールを選択します。ドロップダウンボックスのコンテンツは、データベース情報$( '#stabince')を動的に照会するためです。テキストフィールド:onhidepanel:combobox( "#county")。 $ .ajax({type: "post"、url: "apply/citycombobox_combobox.action ="+upence:false、datape: "json"、success:function( "#city")。編集://編集不可能な状態キャッシュ:// Panelheight:// auto-height fitfield: 'code'、 'note'、function(){$( "#cregicounty") $( '#city')。combobox( 'getValue'); if(city!= ''){$ .ajax({apply "、url:" });}}}); combobox(editable、// false、// panelheight: 'auto'、// auto-height fit value '、' code '、textfield:' note '、onhidepanel:combobox() $( "#cregicounty")。val(str); CountrySearch(NewValue);5。Javaアクションコード
// Query National Administrative District Code Province Public String ProvinceComboBox()Throws Exception {list list = comboboxservice.findprovince(); this.jsonutil(list); nullを返します。 } // Query National Administrative District Code City Public String CityComboBox()Throws Exception {list list = comboboxservice.findcity(州); this.jsonutil(list); nullを返します。 } // Query National Administrative District Code County and District Public String County and District Throws Exception {list list = comboxservice.findcounty(city); this.jsonutil(list); nullを返します。 } // JSONツールメソッドを呼び出し、パラメーターアリストパブリックボイドjsonutil(object councountlist)スロー{httpservletResponse応答= 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)スロー例外{objectmapper objectmapper = new objectMapper(); stringwriter stringwriter = new StringWriter(); objectMapper.writeValue(stringwriter、object); jsonstr = stringwriter.toString(); jsonstrを返します。 }}7。対応するインターフェイスコード
//州の公開リストfindprovince()を照会します。
8。対応するインターフェイス実装クラスコード
// putdown box-- query州パブリックリストfindprovince(){log.info( "===ドロップダウンボックス - クエリ州");基準基準= this.sessionFactory.getCurrentsession()。createCriteria(careaCodetblqg.class); criteria.add(restions.like( "code"、 "%0000")); Criteria.Addorder(Order.Asc( "Code")); return Criteria.list(); } // Putdown Box-Query City Public List FindCity(String Code2){log.info( "===ドロップダウンBox-Query City");文字列id = code2.substring(0,2);基準基準= this.sessionFactory.getCurrentsession()。createCriteria(careaCodetblqg.class); Criteria.Add(restions.like( "code"、id+"%00")); Criteria.Add(restrictions.ne( "code"、code2)); Criteria.Addorder(Order.Asc( "Code")); return Criteria.list(); } //プルダウンボックス - Query County Public List findCounty(string code3){log.info( "===ドロップダウンボックス - クエリ郡");文字列id = code3.substring(0,4);基準基準= this.sessionFactory.getCurrentsession()。createCriteria(careaCodetblqg.class); criteria.add(restions.like( "code"、id+"%")); criteria.add(restrictions.not(restions.like( "code"、 "%01"))); criteria.add(restrictions.ne( "code"、code3)); Criteria.Addorder(Order.Asc( "Code")); return Criteria.list(); }上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。