ページネーションプラグインのクエリ

springmvc・サーブレット構成:

<豆ID = "SessionFactoryの"クラス= "org.mybatis.spring.SqlSessionFactoryBean"> 
<プロパティ名= "データソース" REF = "データソース" />
<! - <プロパティ名= "typeAliases"値= "cn.kgc .util.PageUtil "/> - >
<プロパティ名=" typeAliasesPackage "値= "cn.kgc.vo; cn.kgc.util"/>
<プロパティ名= "mapperLocations"値="クラスパス:マッパー/ *。 XML "/>
<! -分页插件版本使用4的版本- >
<プロパティ名="プラグイン」>
<配列>
<beanクラス= "com.github.pagehelper.PageHelper">
<プロパティ名= "プロパティ" >
<値>方言= MySQLの</値>
</ property>の

</ビーン>
</アレイ>
</ property>の

</豆>

 

ページングクエリ、制御層

パッケージcn.kgc.controller。

輸入cn.kgc.service.EmpService;
輸入cn.kgc.vo.Emp;
輸入com.github.pagehelper.Page。
輸入com.github.pagehelper.PageHelper。
輸入com.github.pagehelper.PageInfo;
輸入org.springframework.beans.factory.annotation.Autowired;
輸入org.springframework.stereotype.Controller。
輸入org.springframework.ui.Model。
輸入org.springframework.web.bind.annotation.RequestMapping。
輸入org.springframework.web.bind.annotation.RequestParam。

輸入はjava.util.List;
輸入java.util.Map;

@Controller
@RequestMapping( "/ EMP")
パブリッククラスEmpController {
@Autowired
プライベートEmpService empService。
@RequestMapping( "/ page.do")
パブリック文字列のshowPage(モデルモデル、@RequestParam(値= "PAGENO"、
偽=、=はdefaultValueに必要な」1" )整数PAGENO、
@RequestParam(値= "DEPTNO"、必要=偽に
はdefaultValue = "-1")整数DEPTNO){
//設定ページフォーマットのみの最初のセットの下で有効な
ページPageHelper.startPage =ページ(PAGENO ,. 3);
//ソート
PageHelper.orderBy(「EMPNO DESC ");
//クエリ情報、影響を受けたページフォーマットの
一覧<地図<文字列、オブジェクト>> EMPLIST = empService.showPage(新新のEmp(DEPTNO));
model.addAttribute(" EMPLIST」、EMPLIST)。
// PageInfo、またはフロントデスクにページ情報を受け入れることができません
PageInfo pageinfo =新しいPageInfo(EMPLIST)。

System.out.println(EMPLIST)。
System.out.println(pageinfo)。
model.addAttribute( "DEPTNO"、DEPTNO)。
model.addAttribute( "pageinfo"、pageinfo)。
「/main.jsp」を返します。
}
}



ページング、マッピングSQL文xmlファイル

<?xml version = "1.0"エンコード= "UTF-8"?> 
<DOCTYPEマッパー!
PUBLIC " - // mybatis.org//DTDマッパー3.0 // EN"
「http://mybatis.org/dtd/mybatis -3- mapper.dtd ">

<マッパーの名前空間=" cn.kgc.mapper.EmpMapper ">


<! -各种查询- >
<。SELECT ID =" selectEmp」のParameterType = "Empの" resultTypeと= "マップ">
EMP Eから*。d.dname、d.loc、Eを選択し、DEPTのDここe.deptno = d.deptno
<試験は= "EMPNO!= null"の場合>
とe.empno =#{EMPNO}
</ IF>
<試験= "DEPTNO = NULLとdeptno列=! - 1"の場合>
とd.deptno =#{DEPTNO}
</ IF>
</ select>の
</マッパー>

basedaoインタフェース

cn.kgc.mapperパッケージ; 

インポートcn.kgc.vo.Emp;
インポートorg.apache.ibatis.annotations.Insert;
インポートorg.apache.ibatis.annotations.Update;

インポートはjava.util.List;
java.utilのインポートクラス。地図;

/ **
* 2019年6月26日に管理者によって作成されます。
* /
パブリックインターフェイスEmpMapper {

//クエリ(detpnoクエリに応じてEMPNOの問い合わせに応じてすべてのクエリ、、)、mapper.xmlの
一覧<地図<文字列、オブジェクト>> SelecTemp(EMP EMP);

}

サービス実装クラス:

パッケージcn.kgc.service。

輸入cn.kgc.mapper.EmpMapper;
輸入cn.kgc.vo.Emp;
輸入com.github.pagehelper.Page。
輸入com.github.pagehelper.PageHelper。
輸入com.github.pagehelper.PageInfo;
輸入org.springframework.beans.factory.annotation.Autowired;
輸入org.springframework.stereotype.Service。
輸入org.springframework.transaction.annotation.Transactional;

輸入javax.annotation.Resource。
輸入はjava.util.List;
輸入java.util.Map;
@Service
@Transactional
publicクラスEmpServiceImplはEmpService {実装
@Autowired
プライベートEmpMapper empMapperを。


@オーバーライド
公共の一覧<地図<文字列、オブジェクト>>のshowPage(EMPのEMP){
empMapper.selectEmp(EMP)を返します。
}
}

結果セット

 

おすすめ

転載: www.cnblogs.com/hong999/p/11106043.html