gpt4 book ai didi

java - Spring引导JPA中的“ConverterNotFoundException”

转载 作者:行者123 更新时间:2023-12-02 03:24:54 27 4
gpt4 key购买 nike

我想通过调用具有 3 个表的自然连接的查询(@Query 方法)来获取 SearchOutput 数据对象。但是当查询运行时它显示错误。

我尝试在我的 Spring Boot Controller 类中获取数据。但由于错误而无法正常工作

package com.example.mysqlproj.model;
import lombok.*;
public class SearchOutput {
private String hotel_name;
private String room_type;
private int price;

}
<小时/>
package com.example.mysqlproj.dao;
import com.example.mysqlproj.model.Room_Type;
import com.example.mysqlproj.model.SearchOutput;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.Collection;
import java.util.Date;
import java.util.List;

public interface RoomTypeDao extends CrudRepository<Room_Type,Integer> {

@Query(value="select new SearchOutput(hotel_name , room_type,(price*(?4)*(?3)*(1.15))) from Room_type natural join Hotel natural join True_contract where (?1 >= start_date and ?2 <= end_date and ?3 <=available_rooms and ?4<= max_adults )", nativeQuery = true)
List<SearchOutput[]> checkHotelList(Date from, Date to, int rooms, int adults, int total_nights);

}

错误:

No converter found capable of converting from type [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap] to type [com.example.mysqlproj.model.SearchOutput]] with root cause 

我的目标是在调用查询时获取 searchOutput 对象数组。有没有什么解决办法。提前致谢

最佳答案

查询的响应类型是 List<Map<String, Object>> .

请将方法返回类型更改为此。

关于java - Spring引导JPA中的“ConverterNotFoundException”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56912088/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com