データベースから対応するリストコレクションを動的に実装し、EasyUIのコンボボックスに表示します。
達成される効果は次のとおりです。
1.データベースのテーブルデザインを図に示します
2。図に示すように、データベースに関連するデータを入力します。図に示されているように、[法的規制]はそれが属する列であるため、その分野の括弧は0です。したがって、それらのフィールドの括弧は1に対応し、[法的および規制]のフィールドカテゴリ体は1です。
3。関連構成:前のブログ//www.vevb.com/article/86381.htmに書いたことがあります
ここにはあまり書きません。キーコードのみを投稿します。
4。対応するアクションコード
パッケージcrj.portal.web.management.action; import java.io.ioexception; Import java.util.list; import javax.servlet.http.httpservletrequest; import.servlet.http.httpservletresponse; Import net.sf.json.json.json.jsonarray; import net.sf.jsonarray; net.sf.json.jsonconfig; Import org.apache.log4j.logger; Import org.apache.struts2.servletactionContext; Import org.hibernate.criteria; import org.hibernate.criter.order; Import com.sun.tool.javac.util.log; crj.portal.web.management.model.cpersontypetbl; Import crj.portal.web.management.service.categoryservice; Import crj.portal.web.management.service.itemservice; Import crj.portal.web.web.management.service.usersererserersererserersererserserserserserser log = logger.getLogger(this.getClass());プライベート文字列ページ。プライベート文字列の行;プライベートストリングLANMUID;プライベートアイテムサービスアイテムサービス; //依存関係インジェクション//プルダウンボックス - クエリ列public文字列categorytbl()スロー例外{list list = itemservice.querylanmu(); this.tojsonarray(list); nullを返します。 } //列IDが所有するカテゴリをクエリpublic string leibie()throws exception {list list = itemservice.queryleibie(lanmuid); this.tojsonarray(list); nullを返します。 } public string tojsonarray(リストリスト)IoException {httpservletResponse response = servletactionContext.getResponse(); httpservletrequest request = servletactioncontext.getRequest(); jsonarray json = jsonarray.fromobject(list); log.info( "json format:" +json.tostring()); Response.setchAracterencoding( "utf-8"); // utf-8 response.getwriter()。write(json.tostring()); // json形式のreturn nullに変換します。 } public string save()throws exception {return this.alllist(); } public Itemservice getItemservice(){return itemservice; } public void setItemservice(itemservice itemservice){this.itemservice = itemservice; } public string getPage(){return page; } public void setpage(string page){this.page = page; } public string getRows(){return rows; } public void setrows(string rows){this.rows = rows; } public userservice getUserservice(){return userservice; } public void setuserservice(userservice userservice){this.userservice = userservice; } public categoryService getCategoryService(){return categoryService; } public void setCategoryService(categoryService CategoryService){this.categoryService = categoryService; } public string getLanmuid(){return lanmuid; } public void setlanmuid(string lanmuid){this.lanmuid = lanmuid; }} 5。対応するインターフェイスコード
パブリックインターフェイスitemservice {//プルダウンボックス - クエリ列パブリックリストquerylanmu()スロー例外。 //プルダウンボックスクエリカテゴリパブリックリストQueryLeibie(String IDS)スロー例外。 } 6.対応するインターフェイス実装クラスコード
public class ItemserviceImpl ImeTieService {logger log = logger.getLogger(this.getClass()); Private SessionFactory SessionFactory; //プルダウンボックス - クエリ列パブリックリストquerylanmu()スロー例外{criteria criteria = this.sessionfactory.getCurrentsession()。 criteria.add(restrictions.eq( "parentid"、0)); Criteria.Addorder(Order.Asc( "CategoryId")); return Criteria.list(); } //プルダウンボックス - クエリカテゴリパブリックリストqueryleibie(string ids)スロー例外{int i = integer.parseint(ids);基準基準= this.sessionFactory.getCurrentsession()。createCriteria(categorytbl.class); criteria.add(restrictions.eq( "parentid"、i)); Criteria.Addorder(Order.Asc( "CategoryId")); return Criteria.list(); } public SessionFactory getSessionFactory(){return SessionFactory; } public void setSessionFactory(sessionFactory sessionfactory){this.sessionFactory = sessionFactory; }} 7。対応するJSPコード
<%@ページ言語= "java" errorpage = "/error.jsp" pageencoding = "utf-8"%> <%@ taglib prefix = "s" uri = "/struts-tags"%> <%string path = request.getContextPath(); /> <!doctype html public " - // w3c // dtd html 4.01 transitional // en"> <html> <head> <title>情報管理</title> <! - jquery-> <cript = "text/javascript" src = "<%= path% charset = "utf-8"> </script> <! - jquery_easyui-> <script type = "text/javascript" src = "<%= path%>/easyui_1.3.2/jquery.easyui.min.js" charset = "utf-8"> type = "text/javascript" src = "<%= path%>/easyui_1.3.2/locale/easyui-lang-zh_cn.js" charset = "utf-8"> </script> <! - EaseyuiデフォルトのCSSフォーマット - > <リンクrel = "styleSheet href = "<%= path%>/easyui_1.3.2/themes/default/easyui.css"/> <! - easyuiアイコンを紹介 - > <link rel = "styleSheet" type = "text/css" href = "<%= path%>/easyui_1.3.2/themes/javiscs"/>>>>>>>>>> javasテーブル情報をダウンロード*/ $(function(){//ドロップダウンボックスでコントロールを選択します。ドロップダウンボックスのコンテンツは、データベース情報$( '#lanmu')。コンボボックス({url: 'itemmanage!categorytbl'、editable:false、//編集可能な状態キャッシュ:false、// 'auto'、//自動高さフィット値: 'categoryid'、 'categoryname:' categoryname '、no cated:' auto '、// $( "#leibie")。combobox( "setvalue"、 ''); $( "#leibie")。 $( '#leibie')。combobox({// url: 'itemmanage!categorytbl'、editable:false、//編集状態キャッシュなし:false、false、 'auto'、// autitatic height fit valuefield: 'categoryid'、textfield: 'categoryname'}); ^)上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。