2017-11-16 13 views
1

私は@RepositoryRestResource のオプションと非常によく似ていますが、エンティティではないオブジェクトだけでページングをしようとしています。エンティティではないオブジェクトでページングを行う方法は?

コード:

public class FloorplanDevice { 

private String FloorplanName; 
private Long FloorplanId; 

private Long DeviceId; 
private String DeviceName; 
private String macAddress; 
private Long groupId; 
private LocatableType deviceType; 

public String getFloorplanName() { 
    return FloorplanName; 
} 

public void setFloorplanName(String floorplanName) { 
    FloorplanName = floorplanName; 
} 

public Long getFloorplanId() { 
    return FloorplanId; 
} 

public void setFloorplanId(Long floorplanId) { 
    FloorplanId = floorplanId; 
} 

public Long getDeviceId() { 
    return DeviceId; 
} 

public void setDeviceId(Long deviceId) { 
    DeviceId = deviceId; 
} 

public String getDeviceName() { 
    return DeviceName; 
} 

public void setDeviceName(String deviceName) { 
    DeviceName = deviceName; 
} 

public String getMacAddress() { 
    return macAddress; 
} 

public void setMacAddress(String macAddress) { 
    this.macAddress = macAddress; 
} 

public Long getGroupId() { 
    return groupId; 
} 

public void setGroupId(Long groupId) { 
    this.groupId = groupId; 
} 

public LocatableType getDeviceType() { 
    return deviceType; 
} 

public void setDeviceType(LocatableType deviceType) { 
    this.deviceType = deviceType; 
} 

public FloorplanDevice() { 
} 

public FloorplanDevice(String floorplanName, Long floorplanId, Long deviceId, String deviceName, String macAddress, Long groupId, LocatableType deviceType) { 
    FloorplanName = floorplanName; 
    FloorplanId = floorplanId; 
    DeviceId = deviceId; 
    DeviceName = deviceName; 
    this.macAddress = macAddress; 
    this.groupId = groupId; 
    this.deviceType = deviceType; 
    } 
} 

このオブジェクトリポジトリを持っていないが、それはコントローラがあります。それでは、どのように私は、ページ番号とサイズ(と、このオブジェクトにページングを行うことができます

@RequestMapping(
     path = arrayOf("/floorplanDevice/{groupId}", "/floorplanDevice/{groupId}/"), 
     method = arrayOf(RequestMethod.GET)) 
open fun getFloorplanDevice(@PathVariable("groupId") groupId: Long): ResponseEntity<*>{ 

var floorplanDevice= floorplanService.getFloorplanDevice(groupId) 
return ResponseEntity(floorplanDevice, HttpStatus.OK) 

} 

をそれが可能ならソートすることもできます)?

public Page<FloorplanDevice> getFloorplanDevice(@PathVariable("groupId") Long groupId, 
      @PageableDefault Pageable pageable) 
    List<FloorplanDevice> list = floorplanService.getFloorplanDevice(groupId); 

    MutableSortDefinition sort = pageable.getSort() != null ? 
      StreamSupport.stream(pageable.getSort().spliterator(), false) 
       .findFirst() 
       .map(it -> new MutableSortDefinition(it.getProperty(), it.isIgnoreCase(), it.isAscending())) 
       .orElse(null) 
      : null; 

    PagedListHolder<FloorplanDevice> pageHolder = new PagedListHolder<>(list, sort); 
    pageHolder.setPage(pageable.getPageNumber()); 
    pageHolder.setPageSize(pageable.getPageSize()); 
    pageHolder.resort(); 

    List<FloorplanDevice> content = pageHolder.getPageList(); 
    Page<FloorplanDevice> page = new PageImpl<>(content, pageable, list.size()); 

    return page; 
} 

答えて

1

はこのような何かを試していただき、ありがとうございます。

 @RequestMapping(
     path = arrayOf("/floorplanDevice/{groupId}/page/{pageNum}/size/{sizeNum}", "/floorplanDevice/{groupId}/page/{pageNum}/size/{sizeNum}/"), 
     method = arrayOf(RequestMethod.GET)) 
open fun getFloorplanDevicePage(@PathVariable("groupId") groupId: Long, @PathVariable("pageNum") pageNum: Int,@PathVariable("sizeNum") sizeNum: Int): ResponseEntity<*>{ 

var floorplanDevice= floorplanService.getFloorplanDevice(groupId) 
var paging= PagedListHolder<FloorplanDevice>(floorplanDevice) 
var setsize= paging.setPageSize(sizeNum) 
if(paging.pageCount>pageNum){ 
var setpage=paging.setPage(pageNum)} 
else{ 
    return throw RuntimeException("page: $pageNum is too big, insert smaller page from 0 to ${paging.pageCount-1}") 
    } 
var pageList= paging.pageList 
return ResponseEntity(pageList, HttpStatus.OK) 

} 
+0

解決していただきありがとうございます。私は別のものを持っている –

0

ソリューション: これはPageListHolderを使用して、私の解決策である私は、Javaの春に

を使用してい

関連する問題