春季数据@Query本机请求

时间:2018-11-29 09:27:06

标签: sql spring spring-data-jpa

具有SQL请求,效果很好,IDEA没有hihglight代码。 但是:

org.springframework.core.convert.ConverterNotFoundException:未找到能够从类型[org.springframework.data.jpa.repository.query.AbstractJpaQuery $ TupleConverter $ TupleBackedMap]转换为类型[ua.com.markovka.model]的转换器.ClientDTO]

如何解决它并获取请求信息?

@Query(value = "SELECT cl.id, cl.name, cl.phone, cl.status, cl.card, ca_date, ca.comment, vi_date, vi_sum from clients cl LEFT JOIN "
        + "(SELECT client_id, Max(date) as ca_date, comment FROM calls GROUP BY client_id) as ca ON ca.client_id=cl.id JOIN "
        + "(SELECT client_id, Max(date) as vi_date, SUM(amount) as vi_sum FROM visits GROUP BY client_id) AS vi ON vi.client_id=cl.id",
    nativeQuery = true
)
List<ClientDTO> findAllDto();

ClientDTO类

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@NoArgsConstructor
@Setter
public class ClientDTO {
    private long clientId;
    private String clientName;
    private String clientPhone;
    private String clientStatus;
    private int card;
    private String lastCallDate;
    private String comment;
    private String visitDate;
    private int visitsSum;

    public ClientDTO(long clientId, String clientName, String clientPhone, String clientStatus, int card, String lastCallDate, String comment, String visitDate, int visitsSum) {
        this.clientId = clientId;
        this.clientName = clientName;
        this.clientPhone = clientPhone;
        this.clientStatus = clientStatus;
        this.card = card;
        this.lastCallDate = lastCallDate;
        this.comment = comment;
        this.visitDate = visitDate;
        this.visitsSum = visitsSum;
    }

    @Override
    public String toString() {
        return  clientName +";"+
                clientPhone + ";"+
                clientStatus + ";"+
                card +";"+
                visitDate +";"+
                visitsSum +";"+
                lastCallDate +";"+
                comment;
    }
}

0 个答案:

没有答案