Peguei a video aula do alura a respeito do jasper.
ele usa um projeto web. com essa servlet
@WebServlet("/gastos")
public class RelatorioServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
String nome = request.getServletContext().getRealPath("/WEB-INF/jasper/gasto_por_mes.jasper");
Connection connection = new ConnectionFactory().getConnection();
Map<String, Object> parametros = new HashMap<String, Object>();
GeradorRelatorio gerador = new GeradorRelatorio(nome, parametros, connection);
gerador.geraPDFParaOutputStream(response.getOutputStream());
connection.close();
} catch (SQLException e) {
throw new ServletException(e);
}
}
}
como eu posso trazer isso pro spring?
@RequestMapping(value = "/report/relatorio", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String form(@RequestParam("id[]") int id[],
@RequestParam("dateIni") @DateTimeFormat(pattern = "dd/MM/yyyy") Date dateIni,
@RequestParam("dateFim") @DateTimeFormat(pattern = "dd/MM/yyyy") Date dateFim,
@RequestParam("horaInit") String horaInit, @RequestParam("minutoInit") String minutoInit,
@RequestParam("horaFim") String horaFim, @RequestParam("minutoFim") String minutoFim) throws JRException {
Calendar cal = Calendar.getInstance();
Relatorio relatorio = new Relatorio();
relatorio.setTag((int) cal.getTimeInMillis());
relatorio.setMachinesIds(id);
relatorio.setDateIni(dateIni);
relatorio.setDateFim(dateFim);
relatorio.setHoraInit(horaInit);
relatorio.setMinutoInit(minutoInit);
relatorio.setHoraFim(horaFim);
relatorio.setMinutoFim(minutoFim);
System.out.println(relatorio.toString());
for (int i = 0; i < relatorio.getMachinesIds().length; i++) {
TemporaryMachineId tempMachine = new TemporaryMachineId();
tempMachine.setMachineId(relatorio.getMachinesIds()[i]);
tempMachine.setTag(relatorio.getTag());
tempMachineDao.gravar(tempMachine);
}
//HttpServletRequest request = null;
//String path = request.getServletContext().getRealPath("/WEB-INF/jasper/reportMaquinaData.jrxml");
//JasperCompileManager.compileReportToFile(path);
return "/relatorio/ok";
}
notem que eu comentei aqui nas ultimas linhas. La no servlet ja recebe o httpservlet. oque eu posso fazer para cegar até o jrxml?