将结果从 HQL 转换为对象
Convert result from HQL into Object
这是我在存储库中的方法 class :
@Query("select max(entry_fee) as maxBuyInFee, max(prize) as maxPrize, max(participants_number) as maxParticipants from Tournament tournament")
FilterMaxValues findFilterMaxValues();
这是我的 FilterMaxValues class :
public class FilterMaxValues {
private Integer maxBuyInFee;
private Integer maxPrize;
private Integer maxParticipants;
如何将此 HQL 的结果转换为 FilterMaxValues 对象?
现在我得到:
No converter found capable of converting from type
[java.util.HashMap] to type [com.test.FilterMaxValues]
您不需要用 @Entity
和 @Table(name="yourDBTable")
注释 FilterMaxValues
class 以便 Spring
可以自动为您进行转换吗?
如果您的 FilterMaxValues
不是实体,您可以使用 projections,例如
interface FilterMaxValues {
Integer getMaxBuyInFee();
Integer getMaxPrize();
Integer getMaxParticipants();
}
这是我在存储库中的方法 class :
@Query("select max(entry_fee) as maxBuyInFee, max(prize) as maxPrize, max(participants_number) as maxParticipants from Tournament tournament")
FilterMaxValues findFilterMaxValues();
这是我的 FilterMaxValues class :
public class FilterMaxValues {
private Integer maxBuyInFee;
private Integer maxPrize;
private Integer maxParticipants;
如何将此 HQL 的结果转换为 FilterMaxValues 对象?
现在我得到:
No converter found capable of converting from type [java.util.HashMap] to type [com.test.FilterMaxValues]
您不需要用 @Entity
和 @Table(name="yourDBTable")
注释 FilterMaxValues
class 以便 Spring
可以自动为您进行转换吗?
如果您的 FilterMaxValues
不是实体,您可以使用 projections,例如
interface FilterMaxValues {
Integer getMaxBuyInFee();
Integer getMaxPrize();
Integer getMaxParticipants();
}