Jelajahi Sumber

分页搜索

yaobo 7 tahun lalu
induk
melakukan
82fdcaef07

+ 7 - 2
src/main/java/cn/efunbox/audio/controller/AdminController.java

@@ -112,8 +112,13 @@ public class AdminController {
 
     @RequestMapping(value = "/search" ,method = RequestMethod.POST)
     public void Search(HttpServletRequest request, HttpServletResponse response){
-        List<Admin> adminList = adminService.SearchAll();
-
+        String page = request.getParameter("page");
+        String size = request.getParameter("size");
+        if(page==null || page.length()<1)
+            page = "0";
+        if(size==null || size.length()<1)
+            size = "0";
+        List<Admin> adminList = adminService.SearchAll(Integer.valueOf(page), Integer.valueOf(size));
 
         for(int i=0; i<adminList.size(); i++){
             adminList.get(i).setSalt("");

+ 1 - 1
src/main/java/cn/efunbox/audio/controller/AudioController.java

@@ -63,7 +63,7 @@ public class AudioController {
             size = "0";
         List<Audio> list = new ArrayList<>();
         if(idGroup!=null && idGroup.length()>0)
-            list = audioService.SearchByIdGroup(Long.valueOf(idGroup));
+            list = audioService.SearchByIdGroup(Long.valueOf(idGroup), Integer.valueOf(page), Integer.valueOf(size));
         else if(name!=null && name.length()>0  && album!=null && album.length()>0)
             list = audioService.SearchByNameAlbum(name, album);
         else if(name!=null && name.length()>0)

+ 11 - 2
src/main/java/cn/efunbox/audio/impl/AdminServiceImpl.java

@@ -2,13 +2,17 @@ package cn.efunbox.audio.impl;
 
 import cn.efunbox.audio.entity.Admin;
 import cn.efunbox.audio.entity.Channel;
+import cn.efunbox.audio.entity.Device;
 import cn.efunbox.audio.repository.AdminRepo;
 import cn.efunbox.audio.repository.ChannelRepo;
 import cn.efunbox.audio.service.AdminService;
 import cn.efunbox.audio.service.ChannelService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -27,8 +31,13 @@ public class AdminServiceImpl implements AdminService {
     }
 
     @Override
-    public List<Admin> SearchAll(){
-        List<Admin> list = adminRepo.findAll();
+    public List<Admin> SearchAll(int page, int size){
+        List<Admin> list = new ArrayList<>();
+        if(size > 1){
+            Pageable pageable = new PageRequest(page, size);
+            list = adminRepo.findAll(pageable).getContent();
+        }else
+            list = adminRepo.findAll();
         return list;
     }
 

+ 5 - 2
src/main/java/cn/efunbox/audio/impl/AudioServiceImpl.java

@@ -43,8 +43,11 @@ public class AudioServiceImpl implements AudioService {
     }
 
     @Override
-    public List<Audio> SearchByIdGroup(Long idGroup){
-        List<Audio> list = audioRepo.findByIdGroup(idGroup);
+    public List<Audio> SearchByIdGroup(Long idGroup, int page, int size){
+        if(size<=0)
+            size = 100;
+        Pageable pageable = new PageRequest(page, size);
+        List<Audio> list = audioRepo.findByIdGroup(idGroup, pageable);
         return list;
     }
 

+ 1 - 1
src/main/java/cn/efunbox/audio/repository/AudioRepo.java

@@ -28,7 +28,7 @@ public interface AudioRepo extends JpaRepository<Audio, Long> {
 
     List<Audio> findByNameContaining(String name);
 
-    List<Audio> findByIdGroup(Long idGroup);
+    List<Audio> findByIdGroup(Long idGroup, Pageable pageable);
 
     List<Audio> findByAlbum( String Album);
 

+ 1 - 1
src/main/java/cn/efunbox/audio/service/AdminService.java

@@ -12,7 +12,7 @@ public interface AdminService {
 
     public Admin GetOne(Long id);
 
-    public List<Admin> SearchAll();
+    public List<Admin> SearchAll(int page, int size);
 
     public List<Admin> SearchById(Long id);
 

+ 1 - 1
src/main/java/cn/efunbox/audio/service/AudioService.java

@@ -14,7 +14,7 @@ public interface AudioService {
 
     public List<Audio> SearchAll(int page, int size);
 
-    public List<Audio> SearchByIdGroup(Long idGroup);
+    public List<Audio> SearchByIdGroup(Long idGroup, int page, int size);
 
     public List<Audio> SearchByName(String name);