springmvc+mybatis3.3出错,代码没有出错,页面也有参数,但是报空指针,求解答

vailter Java程序员  2015-08-12 11:20:50
[DEBUG]2015-08-12 11:24:49,523 org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> cn.sg.controller.BackStageController.QueStoreList(javax.servlet.http.HttpServletRequest)]: java.lang.NullPointerException
[DEBUG]2015-08-12 11:24:49,527 org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> cn.sg.controller.BackStageController.QueStoreList(javax.servlet.http.HttpServletRequest)]: java.lang.NullPointerException
[DEBUG]2015-08-12 11:24:49,527 org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver Resolving exception from handler [public java.util.Map<java.lang.String, java.lang.Object> cn.sg.controller.BackStageController.QueStoreList(javax.servlet.http.HttpServletRequest)]: java.lang.NullPointerException
[DEBUG]2015-08-12 11:24:49,529 org.springframework.web.servlet.DispatcherServlet Could not complete request
java.lang.NullPointerException
at cn.sg.controller.BackStageController.QueStoreList(BackStageController.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
八月 12, 2015 11:24:49 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [sasmvc] in context with path [/CUPBOARD] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at cn.sg.controller.BackStageController.QueStoreList(BackStageController.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
...全文
98 点赞 收藏 5
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
vailter 2015-08-12
好像没有配置mybatis注入
回复
晨曦丶 2015-08-12

你检查下你的BackStageController的第45,是不是在配置文件里面漏配置了某个类。你的这个空指针异常感觉可能是注入依赖出了点问题。
回复
vailter 2015-08-12
DAOImpl层: package cn.sg.dao.impl; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.stereotype.Repository; import cn.sg.dao.ProductDao; import cn.sg.model.Product1; import cn.sg.model.inter.ProductMapper1; import cn.sg.util.MyBatisUtil; @Repository("productDaoImpl") public class ProductDaoImpl implements ProductDao { /** * 获取所有商品 */ public Map<String, Object> qryAllProduct() { SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSessionFactory(); SqlSession session = sqlSessionFactory.openSession(); ProductMapper1 pMapper = session.getMapper(ProductMapper1.class); Map<String, Object> map = null; try { List<Product1> productLists = pMapper.qryAllProduct(); for (Product1 p : productLists) System.out.println(p.getName()+","+p.getNum()+","+p.getArea()); map = new HashMap<String, Object>(); map.put("products", productLists); map.put("success", "true"); } catch (Exception e) { e.printStackTrace(); } finally{ session.close(); } return map; } public Map<String, Object> qryPages(Map<String,Object> params) { SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSessionFactory(); SqlSession session = sqlSessionFactory.openSession(); ProductMapper1 pMapper = session.getMapper(ProductMapper1.class); Map<String, Object> map = null; int page = 0; try { Product1 product1 = pMapper.qryProductNum(params); page = (product1.getPages())/(Integer.parseInt((String) params.get("pageSize"))); System.out.println(page); map = new HashMap<String, Object>(); map.put("pages", page); map.put("success", "true"); } catch (Exception e) { e.printStackTrace(); } finally{ session.close(); } return map; } @Override public Map<String, Object> qryProductByPage(Map<String, Object> params) { SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSessionFactory(); SqlSession session = sqlSessionFactory.openSession(); ProductMapper1 pMapper = session.getMapper(ProductMapper1.class); Map<String, Object> map = null; try { List<Product1> productList = pMapper.qryProductByPage(params); for (Product1 p : productList) System.out.println(p.getName()+","+p.getNum()+","+p.getArea()); map = new HashMap<String, Object>(); map.put("products", productList); map.put("success", "true"); } catch (Exception e) { e.printStackTrace(); } finally{ session.close(); } return map; } }
回复
vailter 2015-08-12
这是Service层: package cn.sg.service; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; import cn.sg.dao.ProductDao; @Service("BackStageService") public class BackStageService { @Autowired @Qualifier("productDaoImpl") private ProductDao productDao; public void setProductDao(ProductDao productDao) { this.productDao = productDao; } public Map<String,Object> qryAllProduct(){ Map<String,Object> map = productDao.qryAllProduct(); return map; } public Map<String,Object> qryPages(Map<String,Object> params){ Map<String,Object> map = productDao.qryPages(params); return map; } public Map<String,Object> qryProductByPage(Map<String,Object> params){ Map<String,Object> map = productDao.qryProductByPage(params); return map; } }
回复
vailter 2015-08-12
这是controller层: package cn.sg.controller; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import cn.sg.constant.BackStageMap; import cn.sg.service.BackStageService; @Controller @RequestMapping("/cupboard") public class BackStageController { @Autowired @Qualifier("BackStageService") private static BackStageService backStageService; public static void setBackStageService(BackStageService backStageService) { BackStageController.backStageService = backStageService; } @RequestMapping("queryStoreList.htm") public String getChoose1(HttpServletRequest request, Model model){ return "backstage/store_list"; } @RequestMapping(value = "storelist.htm",produces = {"application/json;charset=UTF-8"}) @ResponseBody public Map<String,Object> QueStoreList(HttpServletRequest request){ String date = request.getParameter("date"); Integer pageIndex = Integer.parseInt(request.getParameter("pageIndex")); Integer pageSize = Integer.parseInt(request.getParameter("pageSize")); System.out.println(date+"////"+pageIndex+"////"+(pageIndex-1)*pageSize+"////"+pageSize); Map<String,Object> params = new HashMap<String,Object>(); params.put("date",date); params.put("name", ""); params.put("area", ""); params.put("start", (pageIndex-1)*pageSize); params.put("limit", pageSize); Map<String,Object> productmap = backStageService.qryProductByPage(params); for (String key : productmap.keySet()) { System.out.println("key= "+ key + " and value= " + productmap.get(key)); } return productmap; } @RequestMapping(value = "getPages.htm",produces = {"application/json;charset=UTF-8"}) @ResponseBody public Map<String,Object> getPages(HttpServletRequest request){ String date = request.getParameter("date"); Integer pageIndex = Integer.parseInt(request.getParameter("pageIndex")); Integer pageSize = Integer.parseInt(request.getParameter("pageSize")); System.out.println(date+"////"+pageIndex+"////"+(pageIndex-1)*pageSize+"////"+pageSize); Map<String,Object> params = new HashMap<String,Object>(); params.put("date",date); params.put("name", ""); params.put("area", ""); params.put("start", (pageIndex-1)*pageSize); params.put("limit", pageSize); //BackStageMap storeList = new BackStageMap(); Map<String,Object> pagemap = backStageService.qryPages(params); return pagemap; } @RequestMapping(value = "storelistsearch.htm",produces = {"application/json;charset=UTF-8"}) @ResponseBody public Map<String,Object> QueStoreListByParams(HttpServletRequest request){ String date = request.getParameter("date"); String store = request.getParameter("store"); String area = request.getParameter("area"); System.out.println("date:"+date+"***"+"store:"+store+"***"+"area:"+area); BackStageMap storeList = new BackStageMap(); Map<String,Object> map = storeList.getStoreMaps(); return map; } }
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2015-08-12 11:20
社区公告
暂无公告