您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“Spring MVC結合Spring Data JPA如何實現(xiàn)按條件查詢和分頁功能”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“Spring MVC結合Spring Data JPA如何實現(xiàn)按條件查詢和分頁功能”這篇文章吧。
具體內容如下
后臺代碼:在DAO層繼承Spring Data JPA的PagingAndSortingRepository接口實現(xiàn)的 (實現(xiàn)方法主要在SbglServiceImpl.java類中)
前臺表現(xiàn):用kkpaper表現(xiàn)出來
實現(xiàn)效果:
1、實體類
package com.jinhetech.yogurt.sbgl.entity; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.PrimaryKeyJoinColumn; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import org.hibernate.annotations.GenericGenerator; import org.springframework.cache.annotation.Cacheable; @Entity @Table(name="SYS_SBGL") @PrimaryKeyJoinColumn(name = "SBBM") @Cacheable(value = "baseCache") public class Sbgl implements Serializable{ private static final long serialVersionUID = -1423899016746755470L; @Id private String sbbm; private String sbmc; private String sblx; private String sssx; private String ssjd; private String azsj; private String azry; private String sbzt; private String sbjd; private String sbwd; private String wxlxr; private String wxlxdh; private String sbywxcs; private String jzpylyz; private String mqsbcyr; private String bzsm; //setter、getter方法省略 }
2、jsp頁面,看最下面的分頁組件(kkpaper)
resultMap集合是下面Controller中最后查詢和分頁后獲得的所有數(shù)據(jù)信息,resultMap.resultList:resultList是Map集合的屬性,里面存著<key,value>數(shù)據(jù)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> <!doctype html> <c:set var="ctx" value="${pageContext.request.contextPath}" scope="session"/> <html> <head> <title>設備管理</title> <!-- zTree需要的樣式和js --> <link rel="stylesheet" href="${ctx }/yogurtResource/assembly/ztree/css/zTreeStyle.css" rel="external nofollow" type="text/css"> <script type="text/javascript" src="${ctx }/yogurtResource/assembly/ztree/jquery.ztree.core-3.5.js"></script> <script type="text/javascript" src="${ctx }/yogurtResource/assembly/ztree/jquery.ztree.excheck-3.5.js"></script> <!-- 驗證框架 --> <script type="text/javascript" src="${ctx }/yogurtResource/assembly/yogurt/user/formValidate.js"></script> <!-- 修改表單驗證錯誤提示樣式 --> <style type="text/css"> .table-bordered-ul li{ margin:0 5px; float:left} label.error { padding-left: 16px; padding-bottom: 2px; font-weight: bold; color: #F00; } </style> <script type="text/javascript"> function console(consoleTag, userId, stateTag) { // 添加用戶。 if("add" == consoleTag) { $('#formid').prop("action", "${ctx}/sbgl/sbgl_add_list"); } } /** * 搜索。 */ function search() { $('#searchForm').submit(); } </script> </head> <body> <div class="clear"> <div class="panel panel-default yogurt_route" id="yogurt_route"> <a href="${ctx }/home/home_list" rel="external nofollow" >首頁</a> > <a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="navigate();">設備管理</a> > 設備列表 </div> </div> <ul id="bqnum"> <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="navigate();">導航</a> </li> <li><a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="orgTree();">機構</a> </li> </ul> <!-- 根據(jù)條件查詢 --> <div class="clear ppd10" > <form action="${ctx }/sbgl/sbgl_list" method="post" id="searchForm"> <div > 設備名稱: <input type="text" name="serSbmc" id="serSbmc" > </div> <div class="floatleft"> 設備類型: <input type="text" name="serSblx" id="serSblx" > </div> <div class="floatleft"> 所屬市縣: <input type="text" name="serSssx" id="serSssx" > </div> <div class="floatleft"> 基地名稱: <input type="text" name="serJdmc" id="serJdmc" > </div> <div class="floatleft"> 設備狀態(tài): <select class="form-control" name="serSbzt" id="serSbzt"> <option value="">全部</option> <option value="Y">正常</option> <option value="N">異常</option> </select> </div> <button type="submit" class="btn btn-success yogurt_search_button" onclick="search();"> <img src="${ctx }/yogurtResource/images/Panel/search.png" width="18" height="18" /> </button> </form> </div> <!-- 新增、刪除 --> <div class="panel panel-default" > <div class="yogurt_panel_title_core"> <span class="state_bold">共查詢出數(shù)據(jù)結果:<span class="state_red">${resultMap.totalNum}</span>條</span> </div> <div class="more_core3"> <!-- <button type="button" class="btn btn-success yogurt_search_button2" onclick="console('add','');">新增設備</button> --> <button type="button" class="btn btn-success yogurt_search_button2" onclick="window.location.href='${ctx }/sbgl/sbgl_add_list' ">新增設備</button> <button type="button" class="btn btn-success yogurt_search_button2" onclick="console('delete','');">刪除設備</button> </div> </div> <!-- 列表 --> <div class="yogurt_elementsbox_core clear"> <div class="yogurt_elementsbox_table_article" id="yogurt_elementsbox_table_article"> <table id="tableBody" border="0" cellspacing="0" cellpadding="0" class="table yogurt_elementsbox_table"> <thead> <tr class="yogurt_tab_back" onmouseover="this.className='yogurt_tab_trhover'" onmouseout="this.className='yogurt_tab_back'"> <th width="3%"><input type="checkbox" onClick="allchecked(this)"></th> <th width="10%">設備名稱</th> <th width="10%">設備類型</th> <th width="10%">所屬市縣</th> <th width="10%">基地名稱</th> <th width="10%">設備狀態(tài)</th> <th width="10%">維修聯(lián)系人</th> <th width="10%">聯(lián)系電話</th> <th width="10%">設備持有人</th> <th width="17%" >操作</th> </tr> </thead> <tbody id="userTb"> <c:forEach var="sbgl" items="${resultMap.resultList}" varStatus="status"> <tr> <td><input type="checkbox" ></td> <td>${sbgl.sbmc }</td> <td>${sbgl.sblx }</td> <td>${sbgl.sssx }</td> <td>${sbgl.ssjd }</td> <td>${sbgl.sbzt }</td> <td>${sbgl.wxlxr }</td> <td>${sbgl.wxlxdh }</td> <td>${sbgl.mqsbcyr }</td> <td > <a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="console('update', '${user.userId}')"> 修改</a> <a href="javascript:void(0);" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="showRoles('${user.userId}')">| 查看</a> </td> </tr> </c:forEach> </tbody> </table> </div> </div> <!--分頁--> <div > <!--加載分頁組件--> <div id="kkpager"></div> <script type="text/javascript"> var param = ""; $(function() { var totalPage = "${resultMap.totalPage}"; var totalRecords = "${resultMap.totalNum}"; var pageSize = "${resultMap.pageSize}"; var pageNum = parseInt("${resultMap.pageNum}") + 1; //初始化分頁控件 //有些參數(shù)是可選的,比如lang,若不傳有默認值 kkpager.init({ pno: pageNum, //總頁碼 total: "${resultMap.totalPage}", //總數(shù)據(jù)條數(shù) totalRecords: totalRecords, //鏈接前部 hrefFormer: 'sbgl_list', //鏈接尾部 hrefLatter: '', getLink: function(n) { return getInitParam() + "&pageNum=" + n + "&pageSize=" + pageSize; }, lang: { prePageText: '上一頁', nextPageText: '下一頁', totalPageBeforeText: '共', totalPageAfterText: '頁', totalRecordsAfterText: '條數(shù)據(jù)', gopageBeforeText: '轉到', gopageButtonOkText: '確定', gopageAfterText: '頁', buttonTipBeforeText: '第', buttonTipAfterText: '頁' } }); //生成 kkpager.generPageHtml(); $('#mykkpagerselect').val(pageSize); }); function returnoption(pageSize) { window.location.href = getInitParam() + "&pageNum=1&pageSize=" + pageSize; } function getInitParam() { var serSbmc = $('#serSbmc').val(); var serSblx = $('#serSblx').val(); var serSssx = $('#serSssx').val(); var serJdmc = $('#serJdmc').val(); var serSbzt = $('#serSbzt').val(); var attr = "?serSbmc=" + encodeURI(encodeURI(serSbmc)) + "&serSblx=" + serSblx + "&serSssx=" + serSssx + "&serJdmc=" + serJdmc+ "&serSbzt=" + serSbzt; return "${ctx}/sbgl/sbgl_list" + attr; } </script> <!--分頁結束--> </div> <!--分頁end--> </body> </html>
3、Controller(看紅色字體下面那個處理方法)
package com.jinhetech.yogurt.sbgl.controller; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.annotation.Resource; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.view.RedirectView; import com.jinhetech.yogurt.dictionary.crop.service.impl.CropServiceImpl; import com.jinhetech.yogurt.func.entity.Func; import com.jinhetech.yogurt.func.service.FuncService; import com.jinhetech.yogurt.menu.entity.Menu; import com.jinhetech.yogurt.menu.service.MenuService; import com.jinhetech.yogurt.menu.util.MenuUtil; import com.jinhetech.yogurt.organization.entity.OrgTable; import com.jinhetech.yogurt.organization.service.OrgService; import com.jinhetech.yogurt.organization.util.OrgUtil; import com.jinhetech.yogurt.role.entity.Role; import com.jinhetech.yogurt.role.service.RoleService; import com.jinhetech.yogurt.sbgl.dao.SbglDao; import com.jinhetech.yogurt.sbgl.entity.Sbgl; import com.jinhetech.yogurt.sbgl.service.SbglService; import com.jinhetech.yogurt.sbgl.util.SbglUtil; import com.jinhetech.yogurt.user.entity.User; import com.jinhetech.yogurt.user.entity.UserInfo; import com.jinhetech.yogurt.user.service.UserService; import com.jinhetech.yogurt.user.util.UserUtil; import com.jinhetech.yogurt.util.base.BaseController; import com.jinhetech.yogurt.util.base.Constants; import com.jinhetech.yogurt.util.common.TextUtils; import com.jinhetech.yogurt.util.common.UUIDHexGenerator; /** * 系統(tǒng)用戶管理控制類 * * @author Wang Hao * @version 1.0 2014-02-28 初版 */ @Controller("sbglController") @RequestMapping("/sbgl") public class SbglController extends BaseController { // @Resource(name = "sbglDao") // private SbglDao sbglDao; @Resource(name = "sbglService") private SbglService sbglService; /** * 平臺權限管理導航*/ @RequestMapping("/home_list") public ModelAndView home() { return new ModelAndView("iot/permis/permis_home"); } /** * 查詢設備信息列表(支持分頁和多條件查詢)。 * */ @RequestMapping("sbgl_list") @RequiresRoles("sbgl/sbgl_list") public String getUserList(Model model) throws Exception { //顯示設備列表 // List<Sbgl> lst=new ArrayList<Sbgl>(); // lst=(List<Sbgl>) sbglService.getAll(); Map<String, Object> resultMap = null; // 查詢表單或分頁保持請求時 請求參數(shù)的接收 Map<String, String> serArgs = new HashMap<String, String>(); serArgs = SbglUtil.getSelArgsToMap(request);//這個類在下面給出 resultMap = sbglService.getUserBySearch(serArgs, "wxlxdh"); model.addAttribute("resultMap", resultMap); // model.addAttribute("lst", lst); return "sbgl/sbgl_list"; } /** * 新增設備信息列表(支持分頁和多條件查詢)。 * * @author YangZhenghua 2014-5-28 * @throws Exception */ @RequestMapping("sbgl_add_list") @RequiresRoles("sbgl/sbgl_add_list") public String getAddList(Model model) throws Exception { System.out.println("aaa"); model.addAttribute("aaa","aaa"); model.addAttribute("resultMap", "hello world"); return "sbgl/sbgl_add_list"; } /** * 保存、修改用戶信息。 * * @author YangZhenghua 2014-5-28 * @throws Exception */ @RequestMapping("sbgl_save_list") @RequiresRoles("sbgl/sbgl_save_list") public ModelAndView SaveSbgl(Sbgl sbgl) throws Exception { String sbmc=request.getParameter("sbmc"); String sblx=request.getParameter("sblx"); String sssx=request.getParameter("sssx"); String ssjd=request.getParameter("ssjd"); String azsj=request.getParameter("azsj"); String azry=request.getParameter("azry"); String sbzt=request.getParameter("sbzt"); String sbjd=request.getParameter("sbjd"); String sbwd=request.getParameter("sbwd"); String wxlxr=request.getParameter("wxlxr"); String wxlxdh=request.getParameter("wxlxdh"); String sbywxcs=request.getParameter("sbywxcs"); String jzpylyz=request.getParameter("jzpylyz"); String mqsbcyr=request.getParameter("mqsbcyr"); String bzsm=request.getParameter("bzsm"); sbgl.setSbbm(UUIDHexGenerator.generate()); sbgl.setSbmc(sbmc); sbgl.setSblx(sblx); sbgl.setSssx(sssx); sbgl.setSsjd(ssjd); sbgl.setAzsj(azsj); sbgl.setAzry(azry); sbgl.setSbzt(sbzt); sbgl.setSbjd(sbjd); sbgl.setSbwd(sbwd); sbgl.setWxlxr(wxlxr); sbgl.setWxlxdh(wxlxdh); sbgl.setSbywxcs(sbywxcs); sbgl.setJzpylyz(jzpylyz); sbgl.setMqsbcyr(mqsbcyr); sbgl.setBzsm(bzsm); sbglService.save(sbgl); return new ModelAndView(new RedirectView("sbgl_list")); } }
3.2、SbglUtil.java
封裝從前臺傳遞過來的查詢參數(shù)、前臺傳遞過來的分頁參數(shù),都放到Map集合serArgs中
package com.jinhetech.yogurt.sbgl.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import com.jinhetech.yogurt.organization.entity.OrgTable; import com.jinhetech.yogurt.report.entity.Report; import com.jinhetech.yogurt.role.entity.Role; import com.jinhetech.yogurt.user.entity.User; import com.jinhetech.yogurt.user.entity.UserInfo; import com.jinhetech.yogurt.util.common.JSONUtils; import com.jinhetech.yogurt.util.common.TextUtils; /** * 用戶功能模塊工具類。 * * @author YangZhenghua * @version V1.0 2014-5-16 初版 * */ public class SbglUtil { /** * 封裝從前臺傳遞過來的查詢參數(shù)。 * * @author YangZhenghua * @date 2014-6-26 */ public static Map<String, String> getSelArgsToMap(HttpServletRequest request) throws Exception { Map<String, String> serArgs = new HashMap<String, String>(); String serSbmc = request.getParameter("serSbmc"); String serSblx = request.getParameter("serSblx"); String serSssx = request.getParameter("serSssx"); String serJdmc = request.getParameter("serJdmc"); String serSbzt = request.getParameter("serSbzt"); String pageNum = request.getParameter("pageNum") == null ? "1" : request.getParameter("pageNum"); String pageSize = request.getParameter("pageSize") == null ? "10" : request.getParameter("pageSize"); //serArgs.put("serUserName", java.net.URLDecoder.decode(serUserName == null ? "" : serUserName, "UTF-8")); serArgs.put("serSbmc", serSbmc); serArgs.put("serSblx", serSblx); serArgs.put("serSssx", serSssx); serArgs.put("serJdmc", serJdmc); serArgs.put("serSbzt", serSbzt); serArgs.put("pageNum", pageNum); serArgs.put("pageSize", pageSize); return serArgs; } }
3.3、SbglService.java
package com.jinhetech.yogurt.sbgl.service; import java.util.List; import java.util.Map; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.jinhetech.yogurt.sbgl.entity.Sbgl; public interface SbglService { public List<Sbgl> getAll() throws Exception; public Sbgl save(Sbgl sbgl) throws Exception; public Map<String, Object> getUserBySearch(Map<String, String> serArgs, final String sortType) throws Exception; }
3.4、SbglServiceImpl.java (根據(jù)前臺傳遞來的查詢參數(shù)進行查詢,獲得的結果數(shù)據(jù)放到Page objPage參數(shù))
package com.jinhetech.yogurt.sbgl.service.impl; import java.util.ArrayList; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.JoinType; import javax.persistence.criteria.ListJoin; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.jinhetech.yogurt.role.entity.Role; import com.jinhetech.yogurt.sbgl.dao.SbglDao; import com.jinhetech.yogurt.sbgl.entity.Sbgl; import com.jinhetech.yogurt.sbgl.service.SbglService; import com.jinhetech.yogurt.user.entity.UserInfo; import com.jinhetech.yogurt.util.common.PageUtils; import com.jinhetech.yogurt.util.common.TextUtils; @Service("sbglService") @Transactional public class SbglServiceImpl implements SbglService{ @Resource(name = "sbglDao") private SbglDao sbglDao; public List<Sbgl> getAll() throws Exception{ return (List<Sbgl>) this.sbglDao.findAll(); } public Sbgl save(Sbgl sbgl) throws Exception { return sbglDao.save(sbgl); } /** * 查詢用戶信息列表(支持分頁和多條件查詢)。 * * @author YangZhenghua 2014-6-19 */ public Map<String, Object> getUserBySearch(final Map<String, String> serArgs, final String sortType) throws Exception { // 獲得分頁對象pageable,并且在pageable中頁碼是從0開始,設定按照sortType升序排列 Pageable pageable = PageUtils.buildPageRequest(Integer.valueOf(serArgs.get("pageNum")), Integer.valueOf(serArgs.get("pageSize")), sortType); Page<Sbgl> objPage = sbglDao.findAll(new Specification<Sbgl>() { public Predicate toPredicate(Root<Sbgl> root, CriteriaQuery<?> query, CriteriaBuilder cb) { List<Predicate> lstPredicates = new ArrayList<Predicate>(); if (TextUtils.isNotBlank(serArgs.get("serSbmc"))) { lstPredicates.add(cb.like(root.get("sbmc").as(String.class), "%" + serArgs.get("serSbmc") + "%")); } if (TextUtils.isNotBlank(serArgs.get("serSblx"))) { lstPredicates.add(cb.like(root.get("sblx").as(String.class), "%" + serArgs.get("serSblx") + "%")); } if (TextUtils.isNotBlank(serArgs.get("serSssx"))) { lstPredicates.add(cb.like(root.get("sssx").as(String.class), "%" + serArgs.get("serSssx") + "%")); } if (TextUtils.isNotBlank(serArgs.get("serJdmc"))) { lstPredicates.add(cb.like(root.get("jdmc").as(String.class), "%" + serArgs.get("serJdmc") + "%")); } if (TextUtils.isNotBlank(serArgs.get("serSbzt"))) { lstPredicates.add(cb.equal(root.get("sbzt"), serArgs.get("serSbzt"))); } Predicate[] arrayPredicates = new Predicate[lstPredicates.size()]; return cb.and(lstPredicates.toArray(arrayPredicates)); } }, pageable); return PageUtils.getPageMap(objPage); } }
3.4.1、PageUtils.java(分頁數(shù)據(jù)工具類)
package com.jinhetech.yogurt.util.common; import java.util.HashMap; import java.util.Map; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import com.jinhetech.yogurt.util.base.Constants; /** * 分頁數(shù)據(jù)工具類。 * * @author YangZhenghua * @version V1.0 2014-6-24 初版 * */ public class PageUtils { /** * 封裝分頁數(shù)據(jù)到Map中。 */ public static Map<String, Object> getPageMap(Page<?> objPage) { Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(Constants.PAGE_RESULT_LIST, objPage.getContent()); // 數(shù)據(jù)集合 resultMap.put(Constants.PAGE_TOTAL_NUM, objPage.getTotalElements()); // 總記錄數(shù) resultMap.put(Constants.PAGE_TOTAL_PAGE, objPage.getTotalPages()); // 總頁數(shù) resultMap.put(Constants.PAGE_NUM, objPage.getNumber()); // 當前頁碼 resultMap.put(Constants.PAGE_SIZE, objPage.getSize()); // 每頁顯示數(shù)量 return resultMap; } /** * 創(chuàng)建分頁請求。 * * @author YangZhenghua * @date 2014-7-14 * * @param pageNum 當前頁 * @param pageSize 每頁條數(shù) * @param sortType 排序字段 * @param direction 排序方向 */ public static PageRequest buildPageRequest(int pageNum, int pageSize, String sortType, String direction) { Sort sort = null; if (!TextUtils.isNotBlank(sortType)) { return new PageRequest(pageNum - 1, pageSize); } else if (TextUtils.isNotBlank(direction)) { if (Direction.ASC.equals(direction)) { sort = new Sort(Direction.ASC, sortType); } else { sort = new Sort(Direction.DESC, sortType); } return new PageRequest(pageNum - 1, pageSize, sort); } else { sort = new Sort(Direction.ASC, sortType); return new PageRequest(pageNum - 1, pageSize, sort); } } /** * 創(chuàng)建分頁請求(該方法可以放到util類中). */ public static PageRequest buildPageRequest(int pageNum, int pageSize, String sortType) { return buildPageRequest(pageNum, pageSize, sortType, null); } /** * 創(chuàng)建分頁請求 * * @author YangZhenghua * @date 2014-11-12 * * @param pageNum * @param pageSize * @param sort * @return */ public static PageRequest buildPageRequest(int pageNum, int pageSize, Sort sort) { return new PageRequest(pageNum - 1, pageSize, sort); } /** * 創(chuàng)建分頁請求(該方法可以放到util類中). */ public static PageRequest buildPageRequest(int pageNum, int pageSize) { return buildPageRequest(pageNum, pageSize, null, null); } }
4、DAO(SbglDao.java),對,只需要繼承Spring Data JPA的PagingAndSortingRepository接口,Controller中調用其findAll()方法
package com.jinhetech.yogurt.sbgl.dao; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.stereotype.Repository; import com.jinhetech.yogurt.sbgl.entity.Sbgl; import com.jinhetech.yogurt.user.entity.UserInfo; @Repository("sbglDao") public interface SbglDao extends PagingAndSortingRepository<Sbgl, String>, JpaSpecificationExecutor<Sbgl> { }
以上是“Spring MVC結合Spring Data JPA如何實現(xiàn)按條件查詢和分頁功能”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業(yè)資訊頻道!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。