作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的 java spring mvc 应用程序中,我使用以下代码:
存储库:
@Repository
public interface TransactionRepository extends JpaRepository<Transactions ,Long >{
@Query(value = "SELECT sum( value) FROM Transactions inner join Customer on Transactions.customer_id=Customer.id where merchant_id= ?1 and age_class= ?2 ", nativeQuery=true)
public double getOverAllValue(String merchantID,String ageGroup);
}
然后我制作了一个基于此@Repository
的服务:
@Service
public class IncomeDataService {
@Autowired
TransactionRepository transactionRepo;
public ArrayList<Double> dataCollector(int merchantID){
ArrayList<Double> data= new ArrayList<Double>();
for(int i=0;i<10;i++)
data.add( transactionRepo.getOverAllValue(Integer.toString(merchantID),Integer.toString(i)));
return data;
}
然后我尝试使用junit
测试编写的服务:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SEBApplication.class)
public class IncomeDataServiceTest {
@Autowired
IncomeDataService incomeDataService;
@Test
public void testDataCollector() {
System.out.println(incomeDataService.dataCollector(1));
}
}
但是,当我运行测试时,它会提示:
org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract double ee.seb.domain.repository.TransactionRepository.getOverAllValue(java.lang.String,java.lang.String)
最佳答案
将查询的返回类型从原始数据类型 double
更新为 Double
因为您的查询可以返回将被包装类接受的 null
值而不是原始的,所以你的最终查询将是这样的:
@Query(value = "SELECT sum( value) FROM Transactions inner join Customer on Transactions.customer_id=Customer.id where merchant_id= ?1 and age_class= ?2 ", nativeQuery=true)
public Double getOverAllValue(String merchantID,String ageGroup);
关于java - Aop调用异常 : in @Autowieired in JUnit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44094283/
在我的 java spring mvc 应用程序中,我使用以下代码: 存储库: @Repository public interface TransactionRepository extends
我是一名优秀的程序员,十分优秀!