jfinal-ext 关于PoiRender导出excel但是无数据.
使用:jfinal-ext: 3.1.4 jfinal 2.0
代码如下:
UserRecord user= getSessionAttr("user"); String [] header={"编号","证件号码","加入时间","驾龄","电话"}; String [] columns={"id","transport_license","create_time","driving_time","phone_number"}; int userid=user.getInt("id"); List<CarinfoRecord> objs= carInfoService.findCarsByUser(userid); List<Object> data = new ArrayList(); for(int i=0;i<objs.size();i++){ Map<String, Object > map=new HashMap<String, Object>(); map.put(columns[0], objs.get(i).getInt(columns[0])); map.put(columns[1], objs.get(i).getStr(columns[1])); map.put(columns[2], objs.get(i).getStr(columns[2])); map.put(columns[3], objs.get(i).getInt(columns[3])); map.put(columns[4], objs.get(i).getStr(columns[4])); System.out.println(map.get(columns[0])+"0000000000000"); System.out.println(map.get(columns[1])+"1111111111111"); System.out.println(map.get(columns[2])+"2222222222222"); System.out.println(map.get(columns[3])+"3333333333333"); System.out.println(map.get(columns[4])+"4444444444444"); data.add(map); } System.out.println(JSON.toString(objs)); Render poiRender=PoiRender.me(data).fileName("carInfo.xls").headers(header).columns(columns); render(poiRender);
system.out都有数据在。
报错如下:
[ERROR]-[Thread: qtp15565667-17]-[com.jfinal.core.ActionHandler.handle()]: /carInfo/carsToExc java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook at com.jfinal.ext.render.excel.PoiRender.render(PoiRender.java:57) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:93) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:365) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:744) Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:430) at com.jfinal.server.JFinalClassLoader.loadClass(JFinalClassLoader.java:53) ... 26 more 2015-11-18 12:45:17 [ERROR]-[Thread: qtp15565667-17]-[com.jfinal.core.JFinalFilter.doFilter()]: /carInfo/carsToExc java.lang.IllegalStateException: STREAM at org.eclipse.jetty.server.Response.getWriter(Response.java:699) at com.jfinal.render.ErrorRender.render(ErrorRender.java:59) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:126) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:365) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:744)
而且用官方实例:
public void columns() { String[] columns = new String[] { "ACC_NBR", "DEVID", "IMSI" }; String[] headers = new String[] { "电话号码", "设备id", "imsi", "最后上线时间" }; String[] headers2 = new String[] { "电话号码", "设备id", "imsi" }; List<Object> data = Lists.newArrayList(); for (int i = 0; i < 5; i++) { Map<String, Object> map = getMap(i); data.add(map); } render(PoiRender.me(data).fileName("your_file_name.xls").headers(headers).cellWidth(5000).headerRow(2)); } private Map<String, Object> getMap(int i) { Map<String, Object> map = Maps.newHashMap(); map.put("ACC_NBR", "ACC_NBR" + i); map.put("IMSI", "IMSI" + i); map.put("DEVID", "DEVID" + i); map.put("LASTTIME", "LASTTIME" + i); return map; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
引用来自“JFinal”的评论
注意看一下异常信息:
java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook, 缺少 jar 包
回复
多多支持 jfinal 发展
数据封装好了,render(poirender)没反应,怎么返回到浏览器??
回复
我的也是没反应,包都导进去了,debug有数据,浏览器没反应。
注意看一下异常信息:
java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook, 缺少 jar 包