package com.pes_soft.example.ctrler;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.pes_soft.example.constant.IReportFormat;
import com.pes_soft.example.constant.IReportParam;
import com.pes_soft.example.ds.IReportDataSourceProvider;
import com.pes_soft.example.model.JavaBeanColor;
import com.pes_soft.example.model.JavaBeanFruit;
import com.pes_soft.example.model.JavaBeanPerson;
/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "home";
}
/**
* 返回iReport报表视图
* @param model
* @return
*/
@RequestMapping(value = "/report", method = RequestMethod.GET)
public String report(Model model) {
// 报表数据源
JRDataSource jrDataSourceMain_Person = null;
JRDataSource jrDataSourceSub_Color = null;
JRDataSource jrDataSourceSub_Fruit = null;
try {
IReportDataSourceProvider dataSourcePerson = new IReportDataSourceProvider(JavaBeanPerson.class, JavaBeanPerson.getList());
jrDataSourceMain_Person = dataSourcePerson.create(null);
IReportDataSourceProvider dataSourceColor = new IReportDataSourceProvider(JavaBeanColor.class, JavaBeanColor.getList());
jrDataSourceSub_Color = dataSourceColor.create(null);
IReportDataSourceProvider dataSourceFruit = new IReportDataSourceProvider(JavaBeanFruit.class, JavaBeanFruit.getList());
jrDataSourceSub_Fruit = dataSourceFruit.create(null);
} catch (JRException e) {
e.printStackTrace();
}
model.addAttribute("url", "/WEB-INF/jasper/MvcMultiDsCrossReportExample.jasper"); // 报表模板
model.addAttribute("format", IReportFormat.pdf.name()); // 报表输出格式
model.addAttribute("jrMainDataSource", jrDataSourceMain_Person); // 报表主数据源
model.addAttribute("jrColorDataSource", jrDataSourceSub_Color); // 报表子数据源1(柱状图[Bar Chart])
model.addAttribute("jrFruitDataSource", jrDataSourceSub_Fruit); // 报表子数据源2(饼图[Pie Chart])
return IReportParam.IREPORT_VIEW; // 对应jasper-views.xml中的bean id
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
mvc-ireport-multi-ds.rar (19个子文件)
SpingMVC IReport多数据源交叉报表示例.md 123B
pom.xml 5KB
src
test
resources
log4j.xml 1KB
java
com
pes_soft
example
main
webapp
WEB-INF
web.xml 1KB
views
home.jsp 238B
classes
jasper
MvcMultiDsCrossReportExample.jrxml 8KB
jasper-defs.xml 532B
MvcMultiDsCrossReportExample.jasper 77KB
spring
appServlet
servlet-context.xml 2KB
root-context.xml 380B
resources
resources
META-INF
log4j.xml 1KB
java
com
pes_soft
example
model
JavaBeanColor.java 1KB
JavaBeanPerson.java 2KB
JavaBeanFruit.java 1KB
constant
IReportFormat.java 192B
IReportParam.java 455B
ApplicationIReportView.java 855B
ctrler
HomeController.java 3KB
ds
IReportDataSourceProvider.java 1020B
共 19 条
- 1
记录的习惯
- 粉丝: 138
- 资源: 13
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页