我正在尝试进行分页,与@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)
}
那么如何使用页码和大小对此对象进行分页(如果可能还有排序)?
我正在使用java Spring
谢谢
答案 0 :(得分:1)
尝试这样的事情:
<div *ngFor="let rn of store[0].items" class="items">
<div *ngFor="let value of objectValues(rn)">
<div *ngFor="let btn of objectKeys(value)">
{{value[btn]}}
</div>
</div>
</div>
答案 1 :(得分:0)
<强>解决方案:强> 这是我使用PageListHolder的解决方案。
@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)
}