微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

这个错误“java.util.stream.ReferencePipeline$3 不能转换为 org.springframework.data.domain.Page”是什么意思

如何解决这个错误“java.util.stream.ReferencePipeline$3 不能转换为 org.springframework.data.domain.Page”是什么意思

我想根据工作 ID 过滤我的任务

但是当我运行我的代码时出现这个错误

java.util.stream.ReferencePipeline$3 无法转换为 org.springframework.data.domain.Page

如何解决这些问题

这是我的组件

在这里的服务:

public Page<TaskDataDTO> findAll(String workOrderId,Pageable pageable) {
    log.debug("Request to get all TaskData");
    if(workOrderId!=null)
    return (Page<TaskDataDTO>) taskDataRepository.findAll(pageable).stream().filter(x-> x.getWorkOrderId()==workOrderId).map(taskDataMapper::toDto);
    else
        return null;
}

和我的控制器在这里

 @GetMapping("/task-data/{workOrderId}")
public ResponseEntity<List<TaskDataDTO>> getAllTaskData(@PathVariable String workOrderId,Pageable pageable) {
    if(workOrderId!=null)
    {
        log.debug("REST request to get a page of TaskData");
        Page<TaskDataDTO> page = taskDataService.findAll(workOrderId,pageable);
        HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(),page);
        return ResponseEntity.ok().headers(headers).body(page.getContent());
    }
    else {
        return null;
    }
}

任务实体:

   package com.asc.skyalign.domain;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.io.Serializable;

/**
 * A TaskData.
 */
@Document(collection = "task_data")
public class TaskData implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private String id;

    @Field("roll")
    private String roll;

    @Field("azimuth")
    private String azimuth;

    @Field("tilt")
    private String tilt;

    @Field("sector_location_lat")
    private String sectorLocationLat;

    @Field("amt_imei")
    private String amtImei;

    @Field("wakeu_up_interval")
    private String wakeuUpInterval;

    @Field("sector_id")
    private String sectorID;

    @Field("sector_location_long")
    private String sectorLocationLong;

    @Field("task_name")
    private String taskName;

    @Field("task_description")
    private String taskDescription;

    @Field("work_order_id")
    private String workOrderId;

    private WorkOrder workOrder;

    public void setWorkOrder(WorkOrder workOrder) {
        this.workOrder = workOrder;
    }

    public WorkOrder getWorkOrder() {
        return workOrder;
    }

    // jhipster-needle-entity-add-field - JHipster will add fields here
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getRoll() {
        return roll;
    }

    public TaskData roll(String roll) {
        this.roll = roll;
        return this;
    }

    public void setRoll(String roll) {
        this.roll = roll;
    }

    public String getAzimuth() {
        return azimuth;
    }

    public TaskData azimuth(String azimuth) {
        this.azimuth = azimuth;
        return this;
    }

    public void setAzimuth(String azimuth) {
        this.azimuth = azimuth;
    }

    public String getTilt() {
        return tilt;
    }

    public TaskData tilt(String tilt) {
        this.tilt = tilt;
        return this;
    }

    public void setTilt(String tilt) {
        this.tilt = tilt;
    }

    public String getSectorLocationLat() {
        return sectorLocationLat;
    }

    public TaskData sectorLocationLat(String sectorLocationLat) {
        this.sectorLocationLat = sectorLocationLat;
        return this;
    }

    public void setSectorLocationLat(String sectorLocationLat) {
        this.sectorLocationLat = sectorLocationLat;
    }

    public String getAmtImei() {
        return amtImei;
    }

    public TaskData amtImei(String amtImei) {
        this.amtImei = amtImei;
        return this;
    }

    public void setAmtImei(String amtImei) {
        this.amtImei = amtImei;
    }

    public String getWakeuUpInterval() {
        return wakeuUpInterval;
    }

    public TaskData wakeuUpInterval(String wakeuUpInterval) {
        this.wakeuUpInterval = wakeuUpInterval;
        return this;
    }

    public void setWakeuUpInterval(String wakeuUpInterval) {
        this.wakeuUpInterval = wakeuUpInterval;
    }

    public String getSectorID() {
        return sectorID;
    }

    public TaskData sectorID(String sectorID) {
        this.sectorID = sectorID;
        return this;
    }

    public void setSectorID(String sectorID) {
        this.sectorID = sectorID;
    }

    public String getSectorLocationLong() {
        return sectorLocationLong;
    }

    public TaskData sectorLocationLong(String sectorLocationLong) {
        this.sectorLocationLong = sectorLocationLong;
        return this;
    }

    public void setSectorLocationLong(String sectorLocationLong) {
        this.sectorLocationLong = sectorLocationLong;
    }

    public String getTaskName() {
        return taskName;
    }

    public TaskData taskName(String taskName) {
        this.taskName = taskName;
        return this;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public String getTaskDescription() {
        return taskDescription;
    }

    public TaskData taskDescription(String taskDescription) {
        this.taskDescription = taskDescription;
        return this;
    }

    public void setTaskDescription(String taskDescription) {
        this.taskDescription = taskDescription;
    }

    public String getWorkOrderId() {
        return workOrderId;
    }

    public TaskData workOrderId(String workOrderId) {
        this.workOrderId = workOrderId;
        return this;
    }

    public void setWorkOrderId(String workOrderId) {
        this.workOrderId = workOrderId;
    }
    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof TaskData)) {
            return false;
        }
        return id != null && id.equals(((TaskData) o).id);
    }

    @Override
    public int hashCode() {
        return 31;
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "TaskData{" +
            "id=" + getId() +
            ",roll='" + getRoll() + "'" +
            ",azimuth='" + getAzimuth() + "'" +
            ",tilt='" + getTilt() + "'" +
            ",sectorLocationLat='" + getSectorLocationLat() + "'" +
            ",amtImei='" + getAmtImei() + "'" +
            ",wakeuUpInterval='" + getWakeuUpInterval() + "'" +
            ",sectorID='" + getSectorID() + "'" +
            ",sectorLocationLong='" + getSectorLocationLong() + "'" +
            ",taskName='" + getTaskName() + "'" +
            ",taskDescription='" + getTaskDescription() + "'" +
            ",workOrderId='" + getWorkOrderId() + "'" +
            "}";
    }
}

TaskDto 在这里

    package com.asc.skyalign.service.dto;

import java.io.Serializable;

/**
 * A DTO for the {@link com.asc.skyalign.domain.TaskData} entity.
 */
public class TaskDataDTO implements Serializable {

    private String id;

    private String roll;

    private String azimuth;

    private String tilt;

    private String sectorLocationLat;

    private String amtImei;

    private String wakeuUpInterval;

    private String sectorID;

    private String sectorLocationLong;

    private String taskName;

    private String taskDescription;

    private String workOrderId;

    private WorkOrderDTO workOrderDTO;

    public void setWorkOrderDTO(WorkOrderDTO workOrderDTO) {
        this.workOrderDTO = workOrderDTO;
    }

    public WorkOrderDTO getWorkOrderDTO() {
        return workOrderDTO;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getRoll() {
        return roll;
    }

    public void setRoll(String roll) {
        this.roll = roll;
    }

    public String getAzimuth() {
        return azimuth;
    }

    public void setAzimuth(String azimuth) {
        this.azimuth = azimuth;
    }

    public String getTilt() {
        return tilt;
    }

    public void setTilt(String tilt) {
        this.tilt = tilt;
    }

    public String getSectorLocationLat() {
        return sectorLocationLat;
    }

    public void setSectorLocationLat(String sectorLocationLat) {
        this.sectorLocationLat = sectorLocationLat;
    }

    public String getAmtImei() {
        return amtImei;
    }

    public void setAmtImei(String amtImei) {
        this.amtImei = amtImei;
    }

    public String getWakeuUpInterval() {
        return wakeuUpInterval;
    }

    public void setWakeuUpInterval(String wakeuUpInterval) {
        this.wakeuUpInterval = wakeuUpInterval;
    }

    public String getSectorID() {
        return sectorID;
    }

    public void setSectorID(String sectorID) {
        this.sectorID = sectorID;
    }

    public String getSectorLocationLong() {
        return sectorLocationLong;
    }

    public void setSectorLocationLong(String sectorLocationLong) {
        this.sectorLocationLong = sectorLocationLong;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public String getTaskDescription() {
        return taskDescription;
    }

    public void setTaskDescription(String taskDescription) {
        this.taskDescription = taskDescription;
    }

    public String getWorkOrderId() {
        return workOrderId;
    }

    public void setWorkOrderId(String workOrderId) {
        this.workOrderId = workOrderId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof TaskDataDTO)) {
            return false;
        }

        return id != null && id.equals(((TaskDataDTO) o).id);
    }

    @Override
    public int hashCode() {
        return 31;
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "TaskDataDTO{" +
            "id=" + getId() +
            ",workOrderId='" + getWorkOrderId() + "'" +
            "}";
    }
}

谢谢。

解决方法

return (Page<TaskDataDTO>) taskDataRepository.findAll(pageable).stream().filter(x-> x.getWorkOrderId()==workOrderId).map(taskDataMapper::toDto);

上面的行缺少消耗流的终端操作。尝试添加类似 .collect(Collectors.toList())

Here's the package description for java.util.stream

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。