我正在使用Spring MVC,当我尝试执行图表代码时遇到一些问题。 精确地在我的项目中是html格式的模板,但是现在我不得不使用.jsp扩展名。
我的错误:
2019-06-19 14:51:48.364 ERROR 14784 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "Chart.jsp", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "Chart.jsp", template might not exist or might not be accessible by any of the configured Template Resolvers
最重要的代码:
<!-- chart.jsp-->
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
window.onload = function() {
var dps = [[]];
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
exportEnabled: true,
title: {
text: "Simple Column Chart with Index Labels"
},
data: [{
type: "column", //change type to bar, line, area, pie, etc
//indexLabel: "{y}", //Shows y value on all Data Points
indexLabelFontColor: "#5A5757",
dataPoints: dps[0]
}]
});
var xValue;
var yValue;
var indexLabel;
<c:forEach items="${dataPointsList}" var="dataPoints" varStatus="loop">
<c:forEach items="${dataPoints}" var="dataPoint">
xValue = parseInt("${dataPoint.x}");
yValue = parseFloat("${dataPoint.y}");
indexLabel = "${dataPoint.indexLabel}";
dps[parseInt("${loop.index}")].push({
x : xValue,
y : yValue,
indexLabel : indexLabel
});
</c:forEach>
</c:forEach>
chart.render();
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>
控制器:
@Controller
@RequestMapping("/canvasjschart")
public class CanvasjsChartController {
@Autowired
private CanvasjsChartService canvasjsChartService;
@RequestMapping(method = RequestMethod.GET)
public String springMVC(ModelMap modelMap) {
List<List<Map<Object, Object>>> canvasjsDataList = canvasjsChartService.getCanvasjsChartData();
modelMap.addAttribute("dataPointsList", canvasjsDataList);
return "Chart.jsp";
}
}
我想补充一点,其他模板使用百里香。在这种情况下,我也可以将其重写为HTML,但是现在不知道如何。
项目结构: