SpringBoot и Hibernate не могут получить список объектов на основе предоставленных критериев - PullRequest
0 голосов
/ 16 ноября 2018

У меня проблема при попытке получить список объектов из базы данных с использованием SpringBoot и Hibernate / JPA. В базе данных я перечислил RFI с одним из полей, которые должны быть открыты / закрыты / более. Цель состоит в том, чтобы получить полный список всех открытых RFI и вставить их в поле зрения. Когда я запускаю приведенный ниже код, я получаю только кучу консольных выходов с нулевым значением, а последний имеет что-то другое. Подскажите, пожалуйста, что я делаю не так?

Вот мой код ниже модель:

package com.robi.PlanningRfiTracker.model;

    import java.util.Date;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;

    @Entity
    public class Rfi {

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        private String pprnumber;
        private String title;
        private String site;
        private String rfi;
        private Date datesubmitted;
        private String response;
        private String receivedfrom;
        private Date datereceived;
        private String status;
        private String attachment1;
        private String attachment2;
        private String attachment3;
        private String attachment4;
        private String attachment5;
        private String attachment6;
        private String attachment7;
        private String attachment8;
        private String attachment9;
        private String attachment10;


        public Rfi(Long id, String pprnumber, String title, String site, String rfi, Date datesubmitted, String response,
                String receivedfrom, Date datereceived, String status, String attachment1, String attachment2,
                String attachment3, String attachment4, String attachment5, String attachment6, String attachment7,
                String attachment8, String attachment9, String attachment10) {
            super();
            this.id = id;
            this.pprnumber = pprnumber;
            this.title = title;
            this.site = site;
            this.rfi = rfi;
            this.datesubmitted = datesubmitted;
            this.response = response;
            this.receivedfrom = receivedfrom;
            this.datereceived = datereceived;
            this.status = status;
            this.attachment1 = attachment1;
            this.attachment2 = attachment2;
            this.attachment3 = attachment3;
            this.attachment4 = attachment4;
            this.attachment5 = attachment5;
            this.attachment6 = attachment6;
            this.attachment7 = attachment7;
            this.attachment8 = attachment8;
            this.attachment9 = attachment9;
            this.attachment10 = attachment10;
        }


        public Rfi() {
            super();
        }

        public Long getId() {
            return id;
        }

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

        public String getPprnumber() {
            return pprnumber;
        }

        public void setPprnumber(String pprnumber) {
            this.pprnumber = pprnumber;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getSite() {
            return site;
        }

        public void setSite(String site) {
            this.site = site;
        }

        public String getRfi() {
            return rfi;
        }

        public void setRfi(String rfi) {
            this.rfi = rfi;
        }

        public Date getDatesubmitted() {
            return datesubmitted;
        }

        public void setDatesubmitted(Date datesubmitted) {
            this.datesubmitted = datesubmitted;
        }

        public String getResponse() {
            return response;
        }

        public void setResponse(String response) {
            this.response = response;
        }

        public String getReceivedfrom() {
            return receivedfrom;
        }

        public void setReceivedfrom(String receivedfrom) {
            this.receivedfrom = receivedfrom;
        }

        public Date getDatereceived() {
            return datereceived;
        }

        public void setDatereceived(Date datereceived) {
            this.datereceived = datereceived;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getAttachment1() {
            return attachment1;
        }

        public void setAttachment1(String attachment1) {
            this.attachment1 = attachment1;
        }

        public String getAttachment2() {
            return attachment2;
        }

        public void setAttachment2(String attachment2) {
            this.attachment2 = attachment2;
        }

        public String getAttachment3() {
            return attachment3;
        }

        public void setAttachment3(String attachment3) {
            this.attachment3 = attachment3;
        }

        public String getAttachment4() {
            return attachment4;
        }

        public void setAttachment4(String attachment4) {
            this.attachment4 = attachment4;
        }

        public String getAttachment5() {
            return attachment5;
        }

        public void setAttachment5(String attachment5) {
            this.attachment5 = attachment5;
        }

        public String getAttachment6() {
            return attachment6;
        }

        public void setAttachment6(String attachment6) {
            this.attachment6 = attachment6;
        }

        public String getAttachment7() {
            return attachment7;
        }

        public void setAttachment7(String attachment7) {
            this.attachment7 = attachment7;
        }

        public String getAttachment8() {
            return attachment8;
        }

        public void setAttachment8(String attachment8) {
            this.attachment8 = attachment8;
        }

        public String getAttachment9() {
            return attachment9;
        }

        public void setAttachment9(String attachment9) {
            this.attachment9 = attachment9;
        }

        public String getAttachment10() {
            return attachment10;
        }

        public void setAttachment10(String attachment10) {
            this.attachment10 = attachment10;
        }

        @Override
        public String toString() {
            return "Rfi [pprnumber=" + pprnumber + ", title=" + title + ", site=" + site + ", rfi=" + rfi
                    + ", datesubmitted=" + datesubmitted + ", response=" + response + ", receivedfrom=" + receivedfrom
                    + ", datereceived=" + datereceived + ", status=" + status + "]";
        }

    }

RfiDao:

package com.robi.PlanningRfiTracker.dao;

import java.util.List;
import org.springframework.data.repository.CrudRepository;
import com.robi.PlanningRfiTracker.model.Rfi;

public interface RfiDao extends CrudRepository<Rfi, List> {
    List<Rfi> findByStatus(String status);
}

RfiService:

        package com.robi.PlanningRfiTracker.service;

    import java.util.List;
    import com.robi.PlanningRfiTracker.model.Rfi;

    public interface RfiService {
        List<Rfi> rfiStatus(String status);
    }

RfiServiceImpl:



 package com.robi.PlanningRfiTracker.service.RfiServiceImpl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.robi.PlanningRfiTracker.dao.RfiDao;
import com.robi.PlanningRfiTracker.model.Rfi;
import com.robi.PlanningRfiTracker.service.RfiService;

@Service
public class RfiServiceImpl implements RfiService {

    @Autowired
    private RfiDao rfiDao;

    @Override
    public List<Rfi> rfiStatus(String status) {
        return (List<Rfi>) rfiDao.findByStatus(status);
    }

}

И я прикрепил изображение вывода консоли, когда я запускаю этот код выше.

Спасибо Консольный вывод

1 Ответ

0 голосов
/ 16 ноября 2018

Используйте это на интерфейсе crud. Изменить список на длинный

public interface RfiDao extends CrudRepository<Rfi, Long> {
    List<Rfi> findByStatus(String status);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...