面试自我总结2

1.怎么使用poi导出word和excel?

 1.1动态生成excel

  1. //创建HSSFWorkbook对象  
  2. HSSFWorkbook wb = new HSSFWorkbook();  
  3. //创建HSSFSheet对象  
  4. HSSFSheet sheet = wb.createSheet("sheet0");  
  5. //创建HSSFRow对象  
  6. HSSFRow row = sheet.createRow(0);  
  7. //创建HSSFCell对象  
  8. HSSFCell cell=row.createCell(0);  
  9. //设置单元格的值  
  10. cell.setCellValue("单元格中的中文");  
  11. //输出Excel文件  
  12. FileOutputStream output=new FileOutputStream("d:\\workbook.xls");  
  13. wkb.write(output);  
  14. output.flush();  
复制代码

  1.2导出Excel

  1. /创建HSSFWorkbook对象(excel的文档对象)  
  2.       HSSFWorkbook wb = new HSSFWorkbook();  
  3. //建立新的sheet对象(excel的表单)  
  4. HSSFSheet sheet=wkb.createSheet("成绩表");  
  5. //在sheet里创建第一行,参数为行索引(excel的行),可以是0~65535之间的任何一个  
  6. HSSFRow row1=sheet.createRow(0);  
  7. //创建单元格(excel的单元格,参数为列索引,可以是0~255之间的任何一个  
  8. HSSFCell cell=row1.createCell(0);  
  9.       //设置单元格内容  
  10. cell.setCellValue("学员考试成绩一览表");  
  11. //合并单元格CellRangeAddress构造参数依次表示起始行,截至行,起始列, 截至列  
  12. sheet.addMergedRegion(new CellRangeAddress(0,0,0,3));  
  13. //在sheet里创建第二行  
  14. HSSFRow row2=sheet.createRow(1);      
  15.       //创建单元格并设置单元格内容  
  16.       row2.createCell(0).setCellValue("姓名");  
  17.       row2.createCell(1).setCellValue("班级");      
  18.       row2.createCell(2).setCellValue("笔试成绩");  
  19. row2.createCell(3).setCellValue("机试成绩");      
  20.       //在sheet里创建第三行  
  21.       HSSFRow row3=sheet.createRow(2);  
  22.       row3.createCell(0).setCellValue("李明");  
  23.       row3.createCell(1).setCellValue("As178");  
  24.       row3.createCell(2).setCellValue(87);      
  25.       row3.createCell(3).setCellValue(78);      
  26.   //.....省略部分代码  
  27.   
  28.   
  29. //输出Excel文件  
  30.     OutputStream output=response.getOutputStream();  
  31.     response.reset();  
  32.     response.setHeader("Content-disposition", "attachment; filename=details.xls");  
  33.     response.setContentType("application/msexcel");          
  34.     wkb.write(output);  
  35.     output.close();  
  36. retrun null;  

2.说一说你shiro实现安全登录?

1.在maven里加入shiro需要的jar

<!--shiro start-->

<dependency>

<groupId>org.apache.shiro</groupId>

<artifactId>shiro-all</artifactId>

<version>1.2.3</version>

</dependency>

<!-- shiro end-->

在web.xml加上Shiro过滤器配置:


编写shiro的ShiroRealm类:

通过sessionManager来统一集合,并且交付给securityManager来管理;

还有realm,这个其实是用来个人实现用户验证、权限授权功能的一个东西,

它也会被securityManager来管理,等等。总而言之,securityManger是shiro的指挥中心、心脏。

在Spring框架里集成Shiro,加入配置

登录验证控制类实现:

登录和退出时都需要跟设置shiro的session,

登录成功,Session会话过期,需要重新登录,保证系统安全性 

shiro的整体架构图:


当用户访问时,访问信息发送到了securtymanage.authenticator解析用户数据,通过realms去查用户是否正确。

securitymanage自己实现了一套session管理机制,不需借助外部任何web容器,使用cacheManager来缓存用户的角色和权限数据。realm就是连接数据库的一个桥梁。

认证过程:


shiro授权过程






猜你喜欢

转载自blog.csdn.net/qq_37938523/article/details/80920809