自我-PRCは達成商品ページングクエリ
1.1機能解析
クエリーアイテムをページング達成するために使用easyui DataGridコントロール、DataGridコントロールがページング提出する必要が
ページをし、
行パラメータ(ページ:最初の数ページ、行:ページあたりのレコード数)、
背景応答が含まれ、合計レコードの合計数と商品のコレクションは、オブジェクトの表示する 行 JSONオブジェクトを。
1.2PageHelper説明
1.2.1PageHelperリソースロケータ
https://github.com/pagehelper/Mybatis-PageHelper
原則1.2.2PageHelper
クエリの実行前に、SQL文で、ラインPageHelper.startPage(1、10)を追加します。最初のパラメータは、最初の数ページを示し、2番目のパラメータは、ディスプレイごとのレコード数を示します。そのためには、SQLの実行後に声明によると、ページングセットとして記録されます。レコードの合計数が取得する必要がある場合は、その後、必要PageInfoクラスの対象は、オブジェクトは、レコードの合計数は、次のテストコードの外観を得ることができます。
1.2.3PageHelper設定
(設定は設定ファイルをMyBatisの)
<! -設定ページネーションプラグイン- > <プラグイン> <プラグインインターセプター= " com.github.pagehelper.PageHelper " > <! - 設定されたデータベースタイプのOracleは、MySQL、MariaDB、SQLiteの、 HSQLDB、PostgreSQLの6 種のデータベース - > <プロパティ名= " 方言"値= " MySQLの" /> </プラグイン> </プラグイン>
1.3ego、共通
作成PageResultクラス
パッケージcom.bjsxt.ego.beans。 インポートしたjava.io.Serializable; 輸入はjava.util.List; / * * *パッケージのDataGridコントロールは、データモデルを必要とします * * * / パブリック クラス PageResult <T> を実装Serializableを{ プライベートリスト<T> の行。 プライベートロング合計。 公衆リスト<T> GETROWS(){ 戻り行。} 公共 ボイド setRows(リスト<T> 行){ この .rows = 行。} パブリックロングgetTotal(){ 戻り値の合計。} 公共 ボイドsetTotal(ロング合計){ この .total =総。}}
ItemServiceを作成するには、1.4インターフェース
パッケージcom.bjsxt.ego.rpc.service。 輸入com.bjsxt.ego.beans.PageResult; 輸入com.bjsxt.ego.rpc.pojo.TbItem; パブリック インターフェイスItemService { / * * *達成の製品情報ページお問い合わせ * * * / パブリック PageResult <TbItem> selectItemList(整数ページ、整数列); }
ItemServiceImpl実装クラスを作成する1.5
パッケージcom.bjsxt.ego.rpc.service.impl。 輸入はjava.util.List; 輸入org.springframework.beans.factory.annotation.Autowired; 輸入org.springframework.stereotype.Service。 輸入com.bjsxt.ego.beans.PageResult; 輸入com.bjsxt.ego.rpc.mapper.TbItemMapper; 輸入com.bjsxt.ego.rpc.pojo.TbItem; 輸入com.bjsxt.ego.rpc.pojo.TbItemExample; 輸入com.bjsxt.ego.rpc.service.ItemService。 輸入com.github.pagehelper.Page; 輸入com.github.pagehelper.PageHelper; @サービス パブリック クラスが実装ItemService {ItemServiceImpl // 注入マッパーインターフェイスプロキシオブジェクト @Autowired プライベートTbItemMapper tbItemMapperと、 @オーバーライド 公共 PageResult <TbItem> selectItemList(整数ページ、整数列){ // TODO自動生成方法スタブ // 执行分页操作 ページPS = PageHelper.startPage(ページ、行)。 例TbItemExampleは = 新しい新しいTbItemExampleを(); //は、データベースクエリの実行 リストを<TbItem>リスト= tbItemMapper.selectByExample(例)。 PageResult <TbItem>結果= 新しい PageResult <TbItem> (); result.setRows(リスト); result.setTotal(ps.getTotal())。 戻り値の結果; }}
1.6コンフィギュレーションのApplicationContext-dubbo.xml
< -发布ダボ服务- > <!ダボ:サービスのインターフェース = " com.bjsxt.ego.rpc.service.ItemService " REF = " itemServiceImpl " > </ダボ:サービス>
1.7スタートエゴ-RPCサービス-IMPL公開RPCサービス
com.bjsxt.ego.testをパッケージ化。 インポートにjava.io.IOException; 輸入org.springframework.context.support.ClassPathXmlApplicationContext; パブリック クラスProviderTest { 公共 静的 ボイドメイン(文字列[]引数){ / * * *春ロードされた容器、完全な出版サービス * * * / ClassPathXmlApplicationContext交流 = 新しい ClassPathXmlApplicationContext(" 春/ ApplicationContextの-dao.xml " 、 " 春/ ApplicationContextの-service.xmlに" 、 " 春/ ApplicationContextの-tx.xml " 、 " 春/ ApplicationContextの-dubbo.xml " ) ; ac.start(); // 実行するプログラムのブロッキング 試して{ システム。で.read(); } キャッチ(IOExceptionを電子){ // TODO自動生成されたcatchブロック e.printStackTrace(); } ac.stop(); }}
商品ページングクエリ自我マネージャ - ウェブ実現
2.1コンフィギュレーションのApplicationContext-dubbo.xml
< -春のリモートサービスプロキシオブジェクトコンテナ- > <!ダボ:リファレンス・インタフェース = " com.bjsxt.ego.rpc.service.ItemService " 上記ID = " itemServiceProxy " > </ダボ:リファレンス>
ManagerItemServiceを作成するには、2.2インターフェース
パッケージcom.bjsxt.ego.manager.service。 輸入com.bjsxt.ego.beans.PageResult; 輸入com.bjsxt.ego.rpc.pojo.TbItem; パブリック インターフェイスManagerItemService { / * * *完全な製品情報ページお問い合わせ * * * / パブリック PageResult <TbItem> selectItemListService(整数ページ、整数列); }
ManagerItemServiceImpl実装クラスを作成する2.3
パッケージcom.bjsxt.ego.manager.service.impl。 輸入org.springframework.beans.factory.annotation.Autowired; 輸入org.springframework.stereotype.Service。 輸入com.bjsxt.ego.beans.PageResult; 輸入com.bjsxt.ego.manager.service.ManagerItemService。 輸入com.bjsxt.ego.rpc.pojo.TbItem; 輸入com.bjsxt.ego.rpc.service.ItemService。 @サービス パブリック クラスManagerItemServiceImpl実装ManagerItemService { // プロキシオブジェクトリモートサービス注入 @Autowired プライベートItemService itemServiceProxy。 @オーバーライド 公共 PageResult <TbItem> selectItemListService(整数ページ、整数列){ // TODO自動生成方法スタブ リターンitemServiceProxy.selectItemList(ページ、行)。 }}
2.4クラスの作成ItemController
パッケージcom.bjsxt.ego.manager.controller。 輸入org.springframework.beans.factory.annotation.Autowired; 輸入org.springframework.http.MediaType。 輸入org.springframework.stereotype.Controller; 輸入org.springframework.web.bind.annotation.RequestMapping。 輸入org.springframework.web.bind.annotation.RequestParam; 輸入org.springframework.web.bind.annotation.ResponseBody。 輸入com.bjsxt.ego.beans.PageResult; 輸入com.bjsxt.ego.manager.service.ManagerItemService。 輸入com.bjsxt.ego.rpc.pojo.TbItem; @コントローラ パブリック クラスItemController { // 注入サービス对象 @Autowired プライベートManagerItemService managerItemService。 / * ** ■商品情報ページ要求処理クエリ * * * / @RequestMapping(値 = " 項目/リストは" =生成MediaType.APPLICATION_JSON_VALU E + " ;のcharset = UTF-8 " ) @ResponseBody 公共 PageResult <TbItem> itemListの(@RequestParam(はdefaultValue = " 1 " )整数 ページ、 @RequestParam(はdefaultValue = " 30 " )整数行){ リターンmanagerItemService.selectItemListService(ページ、行)。 }}
商品リストに2.5リリース自我マネージャ - ウェブアクセス
pagehelperの詳細についてはブログ