我想使用 jfree 圖表和來自 mysql 數(shù)據(jù)庫的數(shù)據(jù)創(chuàng)建一個餅圖,但我似乎遇到了錯誤。這是我的代碼。我有一個 LocationRepository 我在其中實現(xiàn)我的 sql 查詢 public interface LocationRepository extends JpaRepository<Location, Integer> { //hibernate query language (jpql) @Query("select type,count(type) from location group by type") public List<Object[]> findTypeAndTypeCout(); }我也有我的 ReportUtility 接口,如下所示 public interface ReportUtil { void generatePieChart(String path, List<Object[]> data); }這是我的 ReportUtility 實現(xiàn)類 @Component public class ReportUtilImpl implements ReportUtil { @Override public void generatePieChart(String path, List<Object[]> data) { // TODO Auto-generated method stub DefaultPieDataset dataset = new DefaultPieDataset(); for (Object[] objects : data) { dataset.setValue(objects[0].toString(), new Double(objects[1].toString())); } JFreeChart chart = ChartFactory.createPieChart3D("Location Type Report", dataset); try { ChartUtilities.saveChartAsJPEG(new File(path+"/pieChart.jpeg"), chart, 300, 300); } catch (IOException e) { e.printStackTrace(); } }}最后是控制器 @Controller public class LocationController { @Autowired LocationService service; @Autowired LocationRepository repository; @Autowired ReportUtil reportUtil; @Autowired ServletContext sc; @RequestMapping("/generateReport") public String generateReport() { String path = sc.getRealPath("/"); List<Object[]> data = repository.findTypeAndTypeCout(); reportUtil.generatePieChart(path, data); return "report"; } }
1 回答

慕少森
TA貢獻(xiàn)2019條經(jīng)驗 獲得超9個贊
從錯誤中,LocationRepository
無法創(chuàng)建 bean。LocationRepository
Spring IOC 無法使用您的代碼。用 注釋您的存儲庫@Repository
,以便 spring 創(chuàng)建 bean。
根據(jù)評論更新答案:
從堆棧跟蹤QuerySyntaxException: location is not mapped
中,Location
沒有創(chuàng)建實體。所以,要么創(chuàng)建它,要么使用@Query(nativeQuery=true)
添加回答
舉報
0/150
提交
取消