xml:

<select id="selectList"   resultType="返回的类型_">
SELECT 
          r.*,o.name orgname
          from
          v_r  r,e_o  o
          where  r.createhospital = o.id
<if test="name!=null and  name!=''">
AND  r.name like '%${name}%'
</if>
<if test="telphone!=null and  telphone!=''">
AND  r.telphone like '%${telphone}%'
</if>
<if test="curoperatorOrgid!=null and  curoperatorOrgid!=''">
AND  r.createhospital = #{curoperatorOrgid}
</if>
<if test="cardno!=null and  cardno!=''">
AND  r.cardno like '%${cardno}%'
</if>
<if test="status!=null and  status!=''">
AND  r.status = #{status}
</if>
<if test="code!=null and  code!=''">
AND  r.code like '%${code}%'
</if>
<if test="beg_date!=null and  beg_date!=''">
AND date_format(r.createtime,'%Y-%m-%d') &gt;= #{beg_date}
</if>
<if test="end_date!=null and  end_date!=''">
AND date_format(r.createtime,'%Y-%m-%d') &lt;= #{end_date}
</if>
<if test="sex!=null and  sex!=''">
AND  r.sex = #{sex}
</if>
<if test="nation!=null and  nation!=''">
AND  r.address like '%${nation}%'
</if>
order by r.orderno
</select>

mapper:

public List<实体类名> selectList(
    @Param(value = "name") String name,
    @Param(value = "telphone") String telphone,
    @Param(value = "curoperatorOrgid") Long cur_orgid,
    @Param(value = "cardno") String cardno,
    @Param(value = "status") String status,
    @Param(value = "code") String code,
    @Param(value = "beg_date")String beg_date,
    @Param(value = "end_date")String end_date,
    @Param(value = "sex")String sex,
    @Param(value = "nation")String nation
    );

service:

public List<类名> getReceiverList(String name, String telphone, Long cur_operatorOrgid, String cardno,
String status, String code, String beg_date, String end_date, String sex, String nation) {

return receiverMapper.selectList(name, telphone, cur_operatorOrgid, cardno, status, code, beg_date, end_date,sex, nation);
}

controller:

@RequestMapping(params = "method=exportExcel")
public void exportExcel(String name, String telphone, String cardno, String status, String code,
HttpServletRequest request, HttpServletResponse response, String beg_date, String end_date, String sex,
String nation, String org, ModelMap map, HttpSession session) throws Exception {

Long cur_oOrgid = null;
if (org == null || org.isEmpty()) {
cur_operatorOrgid = ConstantUtil.getSession_Manager(session).getOrgid();
} else {
cur_operatorOrgid = Long.parseLong(org);
}
// 查询受捐者列表
List<类名> receiverList = receiverService.getReceiverList(name, telphone, cur_operatorOrgid, cardno,
status, code, beg_date, end_date, sex, nation);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");

// 首先引入poi-3.7-20101029.jar包
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("sheet1");
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
HSSFRow row = sheet.createRow((int) 0);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
// 表单头
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("序号");
cell.setCellStyle(style);
cell = row.createCell((short) 1);
cell.setCellValue("姓名");
cell.setCellStyle(style);
cell = row.createCell((short) 2);
cell.setCellValue("性别");
cell.setCellStyle(style);
cell = row.createCell((short) 3);
cell.setCellValue("编号");
cell.setCellStyle(style);
cell = row.createCell((short) 4);
cell.setCellValue("身份证号码");
cell.setCellStyle(style);
cell = row.createCell((short) 5);
cell.setCellValue("出生日期");
cell.setCellStyle(style);
cell = row.createCell((short) 6);
cell.setCellValue("联系电话");
cell.setCellStyle(style);
cell = row.createCell((short) 7);
cell.setCellValue("登记时间");
cell.setCellStyle(style);
cell = row.createCell((short) 8);
cell.setCellValue("所在医院");
cell.setCellStyle(style);
cell = row.createCell((short) 9);
cell.setCellValue("状态");
cell.setCellStyle(style);
cell = row.createCell((short) 10);
cell.setCellValue("排队信息");
cell.setCellStyle(style);
// 第四步,创建单元格,并设置值
for (int i = 0; i < receiverList.size(); i++) {
row = sheet.createRow((int) i + 1);
cell = row.createCell((short) 0);
cell.setCellValue(i + 1);
cell.setCellStyle(style);
cell = row.createCell((short) 1);
cell.setCellValue(receiverList.get(i).getName());
cell.setCellStyle(style);
cell = row.createCell((short) 2);
cell.setCellValue(
receiverList.get(i).getSex() == 0 ? "未知" : (receiverList.get(i).getSex() == 1 ? "男" : "女"));
cell.setCellStyle(style);
cell = row.createCell((short) 3);
cell.setCellValue(receiverList.get(i).getCode());
cell.setCellStyle(style);
cell = row.createCell((short) 4);
cell.setCellValue(receiverList.get(i).getCardno());
cell.setCellStyle(style);
cell = row.createCell((short) 5);
cell.setCellValue(sdf2.format(receiverList.get(i).getBirthday()));
cell.setCellStyle(style);
cell = row.createCell((short) 6);
cell.setCellValue(receiverList.get(i).getTelphone());
cell.setCellStyle(style);
cell = row.createCell((short) 7);
cell.setCellValue(sdf.format(receiverList.get(i).getCreatetime()));
cell.setCellStyle(style);
cell = row.createCell((short) 8);
cell.setCellValue(receiverList.get(i).getOrgname());
cell.setCellStyle(style);
cell = row.createCell((short) 9);
cell.setCellValue(receiverList.get(i).getStatus() == 0 ? "未接受" : "已接受");
cell.setCellStyle(style);
cell = row.createCell((short) 10);
cell.setCellValue("第" + receiverList.get(i).getOrderno() + "名");
cell.setCellStyle(style);
}
// 第六步,将文件存到指定位置
try {
String filename = ("导出的文件名.xls");
response.setContentType("application/x-msdownload");// 下载设置
response.setHeader("Content-Disposition",
"attachment;filename=" + new String(filename.getBytes("GBK"), "iso8859-1"));// 下载设置
System.out.println("=============受捐者导出excel=================");
OutputStream ous = response.getOutputStream();// 下载输出流
wb.write(ous);
} catch (Exception e) {
e.printStackTrace();
}
}

html:

<button class="btn btn-default btn-sdtheme"
οnclick="exportExcel()">导出excel</button>

js:

function exportExcel() {
var name = $("#search_name").val();
var telphone = $("#search_phone").val();
var cardno = $("#search_cardno").val();
var status = $("#status").val();
var code = $("#search_code").val();
var beg_date = $("#beg_date").val();
var end_date = $("#end_date").val();
var sex = $("#search_sex").val();
var nation = $("#search_nation").val();
var org = "${orgid}" == 0 ? $("#search_org").val() : "";
location.href = "${ctx}/*******/*******.do?method=exportExcel&name=" + name + "&code=" + code + "&cardno=" + cardno + "&telphone="
+ telphone + "&status=" + status + "&beg_date=" + beg_date + "&end_date=" + end_date + "&sex=" + sex + "&nation=" + nation
+ "&org=" + org;
}

java web导出excel表格(SSM框架 )相关推荐

  1. java实现这个无表头空表格,《java程序导出excel表格是空白的没有数据?》 java怎么导入数据库...

    java程序导出excel表格是空白的没有数据? 看一下是否可以链接上数据库,或者查看一下链接的数据库是否有数据 java从数据库中导出excel poi 建议你使用pageoffice. java ...

  2. java 导入导出excel表格

    java 导入导出excel表格 业务上有需求上传excel表格并读取内容,本文记录一下该方法 表格导入 引入相应的工具包 <dependency><groupId>cn.af ...

  3. java poi导出Excel表格超大数据量解决方案

    Java实现导出excel表格功能,大部分都会使用apache poi,apache poi API 地址 POI之前的版本不支持大数据量处理,如果数据过多则经常报OOM错误,有时候调整JVM大小效果 ...

  4. java io导出excel表格_Java IO 导入导出Excel表格

    1.将excel导入到内存 1. 调用工作簿Workbook的静态方法getWorkbook(),获得工作簿Workbook对象 InputStream in = new FileInputStrea ...

  5. Java,导出Excel表格文件

    引用三方封装的技术框架 Alibaba/EasyExcel JAVA 解析Excel工具EasyExcel Hutool Hutool是一个小而全的Java工具类库,通过静态方法封装,降低相关API的 ...

  6. java后台导出Excel表格

    引言 java后台导出表格一般分两种:注解配置(@Excel)导出和自定义导出 注解配置(@Excel)导出 添加poi依赖 <dependency><groupId>cn.a ...

  7. Java web导出excel文件 - poi

    Javaweb项目加入导出excel功能只需要2个步骤: 1.在需要的controller里面加入下面接口代码: /*** excel导出controller层代码** @param params* ...

  8. excel导出java不完整_有关Java POI导出excel表格中,单元格合并之后显示不全的解决方法。...

    我在table变换excel之后发现合并的单元格不能显示全部边框,在网上找了半天解决方案,终于解决了.具体解决代码如下; /** * 设置合并单元格的边框样式 * * @param sheet 当前表 ...

  9. java poi导出Excel表格(动态表头)

    HSSFWorkbook xssfWorkbook = new HSSFWorkbook(); //创建工作表对象Sheet sheet = xssfWorkbook.createSheet(); / ...

最新文章

  1. Parcelable与Serializable的比较
  2. Verilog以及VHDL所倡导的的代码准则
  3. 数据挖掘 —— 模型评估
  4. html改变下拉框的大小,调整屏幕大小时,HTML导航栏下拉框内容无法正确调整大小...
  5. AI基础:Pandas简易入门
  6. boost::dynamic_bitset模块boost::hash的测试程序
  7. linux日常管理3
  8. 详解C++代码反汇编后的堆栈寄存器EBP和ESP
  9. shell 循环删除进程
  10. Balsamiq Mockups 实例3
  11. mysql索引ab和ba_Mysql中的索引
  12. 网页聊天室php无数据库_无需数据库的PHP聊天室程序
  13. Jmeter使用CSV文件读取大量测试数据
  14. 数据库服务器对硬件配置的五个要求
  15. 7-1 找第k小的数(反思),a++和++a的区别,运算符优先级,递归分制思想
  16. 4.4 测试度量指标体系和质量评估
  17. 线性回归和贝叶斯的线性回归
  18. 树形数据的搜索方法---javascript
  19. 有关刚度矩阵c语言的算法,基于C语言的钻柱有限元单元刚度矩阵计算.PDF
  20. 计算机毕业生晚会主持稿,2011年华中师范大学计算机科学系迎新晚会主持稿

热门文章

  1. 重新学习Mysql数据库1:无废话MySQL入门
  2. 乘云科技受邀出席2022阿里云合作伙伴大会荣获“聚力行远奖”
  3. spring-boot-starter-redis is deprecated as of Spring Boot 1.4, please migrate to spring-boot-starter
  4. unity射击游戏的倍镜
  5. 假设检验:正态性检验的那些bug——为什么对同一数据,normaltest和ktest会得到完全相反的结果?
  6. 手把手教你使用R语言爬虫在气象网站抓取气象数据并分析绘制热力日历图(1)
  7. 离开中国,舍不得淘宝和快递,还有收快递时的菜鸟驿站!
  8. 自学Python之心得体会(一)
  9. 电学计算机专业英语,电学类专业英语.doc
  10. shader-纹理处理-mipmap