日期:2014-05-17 浏览次数:21022 次
<bean id="reportViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="order" value="1"/> <property name="location" value="/WEB-INF/reports.xml"/> </bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> </bean>
<bean id="datasourceCustomerReport" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView"> <property name="url" value="/pages/report/report1.jasper" /> <property name="jdbcDataSource" ref="dataSource" /> </bean>
@RequestMapping(value = "/datasourceCustomer", method = RequestMethod.POST) public ModelAndView datasourceCustomerReport(HttpServletRequest request) { Map<String, String> model = new HashMap<String, String>(); //这段代码是按用户操作分别返回pdf和excel格式的报表 if (request.getParameter("excel") != null) { model.put("format", "xls"); } else { model.put("format", "pdf"); } return new ModelAndView("datasourceCustomerReport", model); }
<bean id="customerReport" class="org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView"> <property name="url" value="/pages/report/report1.jasper" /> </bean>
@RequestMapping(value = "/customer", method = RequestMethod.POST) public ModelAndView customerReport(HttpServletRequest request) { Map<String, Object> model = new HashMap<String, Object>(); List data = reportService.customerReport(); model.put("data", data); ... return new ModelAndView("customerReport", model); }
@Override public List customerReport() { Session session = sessionFactory.getCurrentSession(); return session.createCriteria(CustomerBaseInfo.class).list(); }
public class ReportDaoImpl implements ReportDao { private JdbcTemplate jdbcTemplate; public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } @Override public List jdbcCustomerReport() { return jdbcTemplate.queryForList("select name, listlaiyuan, yejie from customerbasei