私は最近Easyiを学びましたが、それは非常に便利で、インターフェイスが美しいことがわかりました。ここに学習体験を書き留めてください。このブログでは、SSHと簡単にDatagridのページネーションディスプレイを実装しています。追加、変更、削除、バッチ削除などのその他の機能は、後で1つずつ記載されます。
まず、達成するための効果を見てみましょう。ページごとに5行のデータが表示されたら:
ページごとに10行のデータが表示される場合、効果は次のとおりです。
具体的な手順:
1. Easyiをダウンロードして環境を構築します。
2。SSHプロジェクトを構築すると、プロジェクト全体のディレクトリ構造が図に示されています。
3. Oracleデータベースでテーブル学生を作成します。次の6行のデータを入力します。追加操作はまだ実装されていないため、最初にデータベーステーブルにデータを追加します。デフォルト値は1行あたり5つのデータです。そのため、ページングテストを容易にするために、少なくとも6行のデータを入力してください。
4。Web.xml構成
<?xml version = "1.0" encoding = "utf-8"?> <web-appバージョン= "2.5" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instcance" xsi:schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <! - sttus2フィルター - > <フィルター> <フィルター> Struts2 </filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter </filter-class> </filter> <filter-mapping> <filter-name> struts2 </filter-name> <url-pattern>/*</url-pattern> <リスナークラス> org.springframework.web.context.contextloaderlistener </ristener-class> </ristener> <! - ApplicationContext.xmlの物理的位置の配置 - > <context-param> <param-name> contextconfiglocation </param-mal> classcontext.xml </param-value> </context-param> </web-app>
5。ApplicationContext.xmlの構成
<?xml version = "1.0" encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns:Context = "http://www.springframework.org/schema/context" xmlns:aop = "http://www.springframework.org/schema/aop" xmlns:tx = " xsi:schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www. http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/spring--1.5.5.x. http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/spring-tx-2.5.xt-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-tx-to Resource = "ApplicationContext_bean.xml"/> <Import resource = "applicationContext_db.xml"/> </beans>
6. com.modelでモデルクラスの学生.javaを作成します
パッケージcom.model; public class student {string sustentid; //プライマリキー文字列名; // name string gender; // gender string age; // age public string getStudentid(){return studentid; } public void setstudentid(string sustentid){this.studentid = dustentid; } public string getname(){return name; } public void setName(string name){this.name = name; } public string getGender(){return gender; } public void setgender(string gender){this.gender = gender; } public string getage(){return age; } public void Setage(string age){this.age = age; }} 7. desudent.javaに従って、対応するマッピングファイルsustent.hbm.xmlを生成します
<?xml version = "1.0"?> <!doctype hibernate-mapping public " - // hibernate/hibernateマッピングDTD 3.0 // en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <! 3.4.0.cr1-> <hibernate-mapping> <class name = "com.model.student" table = "sudent name"> <id name = "desutent" etpe = "java.lang.string"> <column name = "desutent" /> <generator />> < /id> <propertial name = "name" Type = "> < /> < name = "gender" type = "java.lang.string"> <column name = "gender"/> </property name = "age" type = "java.lang.String"> <column name = "age"/> </property> </class> </hibernate-mapping>
8。インターフェイスStudentService.javaを書き込みます
パッケージcom.service; import java.util.list; public interface dustenterservice {public list getstudentlist(string page、string rows)スロー例をスロー; 9.インターフェイス実装クラスStudentServiceImpl.javaを作成します
パッケージcom.serviceimpl; import java.util.list; import org.hibernate.sessionfactory; import com.service.studentservice; public class sustentserviceimplを実装している{private SessionFactoryFactory; //ページに従ってデータを取得し、ページごとの数行のデータを取得しますパブリックリストGetStudEntList(String Page、String rows){//デフォルト値の場合は、currentpage = integer.parseint((page == null || page == "0") 「10」://ページごとの行何行= this.sessionFactory.getCurrentsession()。返品リスト。 } //統計合計でどれだけのデータがあるかをpublic inttudenttotal()throws exception {this.sessionfactory.getCurrentssession()。 } public SessionFactory getSessionFactory(){return SessionFactory; } public void setSessionFactory(sessionFactory sessionfactory){this.sessionFactory = sessionFactory; }} 10。データベースApplicationContext_db.xmlに接続するために構成ファイルを構成する
<?xml version = "1.0" encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns:Context = "http://www.springframework.org/schema/context" xmlns:aop = "http://www.springframework.org/schema/aop" xmlns:tx = " xsi:schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www. http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/spring--1.5.5.x. http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/ Beanを使用したソース - > <Bean Id = "DataSource" Destroy-Method = "close"> <! - データベースドライバーの定義 - > <プロパティ名= "driverclass"> <balue> oracle.jdbc.driver.oracledriver </value> </property> < <値> jdbc:oracle:thin:@localhost:1521:orcl </value> </property> <! - データベースのユーザー名を定義します - > <プロパティ名= "ユーザー"> <値> lhq </property> <! <値> 1 </value> </property> <Property name = "maxpoolsize"> <balue> 40 </value> </property> <property name = "maxidletime"> <balue> 1800 </value> </property> <property name = "acchireincrement"> <value> 2 </value> </property> <propertion "> </</</</</</</</</< name = "initialpoolsize"> <value> 2 </value> </property> <property name = "idleconnectiontestperiod"> <value> 1800 </value> </property name> <property name = "acchiretryattempts"> 30 </value> </property> <property name = "breakafteracquireurure"> </value> < name = "testConnectionOnCheckout"> <balue> false </value> </property> </bean> < <プロパティ名= "hibernateProperties"> <props> <prop key = "hibernate.dialect"> org.hibernate.dialect.oracle10gdialect </prop> </props> </property> <! - pojoのマッピングファイルを定義する - > <プロパティ名= "マッピングルーズ"> </list> </property> </bean> <! - トランザクションインターセプターを構成 - > <bean id = "transactionmanager"> <property name = "sessionfactory" ref = "sessionfactory"/> </bean> <tx:アドバイスid = "txadvice" transaction-manager = "transactionmanager" /> <! - 保存、削除、および更新から始まるメソッドのみを実行できます - > <tx:メソッド名= "delete*" propagation = "requent" /> <tx:method name = "update*" propagation = "required" /> <tx: "oppagation =" "read-andly ="をサポートします " />> < <aop:config> <aop:pointcut id = "interceptorpointcuts" expression = "execution(*com.serviceimpl ..*。*(..)" /> <! - クラスインターフェイスを実装するパッケージの場所 - > <aop:Advisor Advice-Ref = "Txadvice" PointCut-ref = " /< /a>
11。コントロールレイヤーにdustentaction.javaタイプを書きます
パッケージcom.action; import java.util.list; import javax.servlet.http.httpservletrequest; Import javax.servlet.http.httpservletresponse; Import net.sf.json.jsonobject; Import org.apache.log4j.logger; import.apache.struts2.struts2.truts2. com.service.studentservice; public class studentaction {static logger log = logger.getLogger(desutent.class);プライベートJsonObject jsonobj;プライベート文字列の行; //各ページに表示されるレコードの数プライベート文字列ページ;リストlist = student_services.getStudentList(ページ、行); this.tobejson(list、student_services.getStudentTotal()); nullを返します。 } // jsonフォーマットに変換しますpublic void tobejson(リスト、int total)スロー例外{httpservletresponse応答= servletactioncontext.getResponse(); httpservletrequest request = servletactioncontext.getRequest(); jsonobject jobj = new jsonobject(); // new a json jobj.accumulate( "total"、合計); //合計は、合計jobj.accumulate( "rows"、list); // rowは表示されたページ応答を表すデータです。 Response.getWriter()。write(jobj.tostring()); // json形式に変換log.info(jobj.tostring()); } public Studentservice getStudent_Services(){return Student_Services; } public void setStudent_services(dustentionervice sustent_services){this.student_services = sustent_services; } public void setjsonobj(jsonobject jsonobj){this.jsonobj = jsonobj; } public void setrows(string rows){this.rows = rows; } public void setpage(string page){this.page = page; }} 12。Springの依存関係インジェクションApplicationContext_bean.xml構成ファイルを書き込みます
<?xml version = "1.0" encoding = "utf-8"?> <beans xmlns = "http://www.springframework.org/schema/beans" xmlns:xsi = "http://www.w3.org/2001/xmlschema-instance" xmlns:Context = "http://www.springframework.org/schema/context" xmlns:aop = "http://www.springframework.org/schema/aop" xmlns:tx = " xsi:schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www. http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/spring--1.5.5.x. http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/ - > <bean id = "desuted_service"> <プロパティ名= "sessionfactory"> <ref bean = "sessionfactory"> </ref> </property> </bean> <! - コントロールレイヤーID = "desudent_action"> <property name = "desudent_service"> <ref bean = "suduent_service"/>> </</bean> </bean> </bean> </bean
13。struts.xml構成ファイルを書き込みます
<?xml version = "1.0" encoding = "utf-8"?> <!doctype struts public " - // apacheソフトウェア財団// dtd struts configuration 2.0 // en" "http://struts.apache.org/dtds/struts-2.0.dtd"学生情報 - > <アクションname = "getallstudentaction" method = "getallstudent"> <result type = "json"> </result> </action> </package> </struts>
14。JSPを書きます---- index.jsp
<%@ page Language = "Java" PageEncoding = "utf-8" iselignored = "false"%> <%string path = request.getContextPath(); "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv =" content-type "content =" text/html; charset = utf-8 "> <tittle> box </titep </</jquery- <> <cript = <> <> <cript = <<> <cript = <> <cription src = "<%= path%>/js/easyui/jquery-1.8.0.min.js" charset = "utf-8"> </script> <! - jquery_easyuiの紹介 - > <スクリプトタイプ= "text/javascript" src = "<%= path% charset = "utf-8"> </script> <! - jquery_easyuiの紹介 - > <スクリプトタイプ= "text/javascript" src = "<%= path%>/js/easyui/jquery.easyui.min.js" charset = "utf-8"> src = "<%= path%>/js/easyui/locale/easyui-lang-zh_cn.js" charset = "utf-8"> </script> <! - easeyuiデフォルトのcss形式 - > <link rel = "styleSheet" type = "text/css" href = "<%= path%>/js/easyui/themes/default/easyui.css"/> <! - easyui smallアイコン - > <link rel = "styleSheet" text/css "href =" < $( '#mydatagrid')。datagrid({title: 'datagrid instance'、iconcls: 'icon-ok'、width:600、pagesize:5、//デフォルトの選択ページはページ1ページあたりのデータの5行です:[5、10、15、20]、[5、10、15、20]、//行の背景。 collapsible : true,//Show foldable button toolbar:"#tb",//This should be used when adding, deleting, and modifying buttons url:'getAllStudentAction.action',//url calls Action method loadMsg: 'Data loading...', singleSelect:true,// When true, you can only select a single row fitColumns:true,//Allow the table to automatically scale to suit the parent container // sortName: 'xh'、//データテーブルが初期化されたときにソートするために使用される列// sortorord: 'desc'、//「asc」または「desc」(正または逆のオーダー)であるソート順序を定義します。 Remotesort:false、frozencolumns:[[{field: 'ck'、checkbox:true}]]、pagination:true、// pagination rownumbers:true // line number}); }); </scrip> </head> <body> <h2> <b> datagrid easeii data-options = "field: 'name'、width:100、align: 'center'"> name </th data-options = "field: 'gender'、width: 'center:' center '"> gender </th> <th data-options = "field:' age '、width:100、' center: '> age </the </the </th> </body> </html>15.プログラムを開始し、テストのためにhttp:// localhost:8080/easyui/index.jspを入力します。
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。