这是存储库:
@Query(value = "select u.balance from User u where u.name=:name")
float toGetBalance(@Param("name") String name);
这是DAO界面:
boolean checkBalance(String userName, float totalPrice);
这是服务
@Transactional(readOnly = true)
@Override
public boolean checkBalance(String userName, float totalPrice) {
if (userRepository.toGetBalance(userName) < totalPrice) {
return false;
} else {
return true;
}
}
,这是错误信息:
org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract float com.repository.UserRepository.toGetBalance(java.lang.String)
并且余额的类型是浮动的!
出了什么问题?
答案 0 :(得分:3)
将存储库的签名更改为
items fetched. testing Optional("my name 1"), myField2 Optional("1"), whose image is
External Data Reference: <self = 0x1702940f0 ; path = nil ; length = 13127>
items fetched. testing Optional("my Name 2"), myField2 Optional("1"), whose image is
External Data Reference: <self = 0x170294140 ; path = 735DB08E-2727-4F01-91C9-914C8A3DD170 ; length = 6826295>
如果在给定@Query(value = "select u.balance from User u where u.name=:name")
Float toGetBalance(@Param("name") String name);
null
答案 1 :(得分:1)
@Query(value = "select u.balance from User u where u.name=:name")'
'Float toGetBalance(@Param("name") String name);
出现此异常是因为名称不存在或余额= NULL如果表中的所选记录是 因此查询结果没有输出。 Spring JPA无法将结果绑定为返回类型Float。
Null return value from advice does not match primitive return type for: public abstract float com.repository.UserRepository.toGetBalance(java.lang.String)