我正在尝试计算特定年份范围输入的入学人数
但为什么我会得到这个例外(检查了一些现有的答案,但无法弄明白。)
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Value [null] cannot be converted to a JRDataSource
这是我的控制器
@RequestMapping(value ="/BMIbyage",method = RequestMethod.GET)
public ModelAndView BMIbyage(ModelAndView modelAndView, ModelMap model, Map<String, Object> map,HttpServletRequest request,
@RequestParam("syear") int syear,@RequestParam("eyear") int eyear,HttpSession session){
String childid = (String) session.getAttribute("childid");
List<AdmissionSummery> asum = new ArrayList<AdmissionSummery>();
List<PatientDetails> patientdetail = patientService.listpatient();
for(int i=syear;i<=eyear;i++){
asum.add(new AdmissionSummery());
int no=0;
for(int j=0;j<patientdetail.size();j++){
float bmi = patientService.listPatient(patientdetail.get(j).getChildid()).get(0).getBmi();
if(bmi<18.5){
no=no+1;
asum.get(asum.size()-1).setNooftime(no);
}
System.out.println("no"+no);
System.out.println("j"+j);
asum.get(asum.size()-1).setDuration(syear+" "+"-"+" "+eyear);
asum.get(asum.size()-1).setYear(i);
System.out.println("BMI"+bmi);
}
System.out.println("i"+i);
}
JRDataSource datasource = new JRBeanCollectionDataSource(asum);
model.addAttribute("datasourcebmireportA", datasource);
model.addAttribute("format", "pdf");
modelAndView = new ModelAndView("pdfReportViewaddsummeryA", model);
return modelAndView;
}
这里是jsp
<tr>
<td ><a href="#"><div class="box">
<form action="BMIbyage">
<table width="584">
<tr>
<td width="172">
<font color="black">BMI value 18.5kg/m2</font></td>
<td width="82">
<select name="syear">
<option value="Pleaseselect">----</option>
<%for(int j=1980;j<=2030;j++)
{
%>
<option value="<%=j%>"><%=j%></option>
<%
}
%>
</select>
</td>
<td width="20"> to </td>
<td width="178">
<select name="eyear">
<option value="Pleaseselect">----</option>
<%for(int j=1980;j<=2030;j++)
{
%>
<option value="<%=j%>"><%=j%></option>
<%
}
%>
</select>
</td>
<td width="108"><input type="submit" value="Generate"></td>
</tr>
</table>
</form>
</div></a></td>
</tr>
这是jasper-views.xml
<bean id="pdfReportViewaddsummeryA" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView" p:url="/WEB-INF/Reports/BMIReport.jasper" p:reportDataKey="datasourceadmissionreportA" />
答案 0 :(得分:1)
jasper-views.xml更改的问题
<bean id="pdfReportViewaddsummeryA" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView" p:url="/WEB-INF/Reports/BMIReport.jasper" p:reportDataKey="datasourcebmireportA" />
而不是
<bean id="pdfReportViewaddsummeryA" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView" p:url="/WEB-INF/Reports/BMIReport.jasper" p:reportDataKey="datasourceadmissionreportA" />