상품 페이징 쿼리 자아-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)를 추가, 첫 번째 매개 변수는 두 번째 매개 변수는 디스플레이 당 레코드 수를 나타냅니다, 처음 몇 페이지를 나타냅니다 . 그래서 SQL의 구현은 성명에 따라 페이징 세트로 기록됩니다 후. 총 레코드 수를 확보해야하는 경우, 다음, 필요 PageInfo 클래스의 주제는, 오브젝트는 총 레코드 수, 다음 테스트 코드 모양을 얻을 수 있습니다.
1.2.3PageHelper 구성
(구성 설정 파일을 MyBatis로)
<! - 구성 매김 플러그인 -> <플러그인> <플러그인 인터셉터 = " com.github.pagehelper.PageHelper " > <! - 설정 데이터베이스 유형 오라클, MySQL은, MariaDB, SQLite는, HSQLDB, PostgreSQL의 리우 DATABASE의 ON - > <속성 이름 = " 방언 " 값 = " MySQL은 " /> </ 플러그인> </ 플러그인>
1.3ego - 일반
만들기 PageResult 클래스
com.bjsxt.ego.beans 패키지; 수입 java.io.Serializable을; 수입은 java.util.List; / * * *封装데이터 그리드控件需要的数据模型 * * * / 공용 클래스 PageResult <T> 를 구현 직렬화 { 개인 목록 <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 (쪽 정수 정수 행); }
1.5 만들기 ItemServiceImpl 구현 클래스
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; @Service 공공 클래스 ItemServiceImpl 구현 ItemService { // 注入매퍼接口代理对象 @Autowired 개인 TbItemMapper tbItemMapper; @Override 공개 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 { 공공 정적 무효 메인 (문자열 []에 args) { / * * *加载스프링容器,完成服务发布 * * * / ClassPathXmlApplicationContext 교류 = 새로운 ClassPathXmlApplicationContext ( " 스프링 / 애플리케이션 컨텍스트 - dao.xml " , " 스프링 / 애플리케이션 컨텍스트 -service.xml " , " 봄 / ApplicationContext에-tx.xml " , "봄 / ApplicationContext를-dubbo.xml " ); ac.start (); // 실행 차단 프로그램 은 try { 시스템. 에 .read (); } 캐치 (IOException가 E) { // 해야할 일 자동 생성 된 블록 캐치 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 (쪽 정수 정수 행); }
2.3 만들기 ManagerItemServiceImpl 구현 클래스
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; @Service 공공 클래스 ManagerItemServiceImpl 구현 ManagerItemService { // 注入的是远程服务的代理对象 @Autowired 개인 ItemService itemServiceProxy; @Override 공공 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; @Controller 공공 클래스 ItemController의 { // 注入서비스对象 @Autowired 개인ManagerItemService managerItemService; / * ** *处理商品信息分页查询的请求 * * * / @RequestMapping (값 = " 항목 /리스트 " 생산 = MediaType.APPLICATION_JSON_VALU E +를 " ; 문자셋 = UTF-8 " ) @ResponseBody 공개 PageResult <TbItem> itemList에 (@RequestParam (DEFAULTVALUE = " 1 " ) 정수 페이지 @RequestParam (DEFAULTVALUE = " 30 " ) 정수 행) { 복귀 managerItemService.selectItemListService (페이지 행); }}
제품 목록 2.5 출시 자아 관리자 - 웹 액세스
pagehelper에 대한 자세한 블로그