HTTP Status 500 - Request processing failed
来源:9-6 购物车模块所有功能自测
拾灬荒灬者
2018-05-05
HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException
type Exception report
message Request processing failed; nested exception is java.lang.NullPointerException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:943)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
root cause
java.lang.NullPointerException
com.mmall.service.Impl.CartServiceImpl.add(CartServiceImpl.java:53)
com.mmall.controller.portal.CartController.add(CartController.java:45)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:748)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.75 logs.
我把这一章所有的代码从老师那里复制了一遍,重新运行还是不行。。。
这里的问题时,我用非管理员账号登录可以成功,使用管理员账号会报500错误
4回答
-
Geely
2018-05-06
java.lang.NullPointerException
com.mmall.service.Impl.CartServiceImpl.add(CartServiceImpl.java:53)检查一下这个的空指针,看看是不是数据库里的数据导致的。
20 -
拾灬荒灬者
提问者
2018-05-06
确实是数据库中的数据导致的,购物车里面有一条数据,uswerId是admin的id里面的checked值为null,删除了以后,再重新添加就不会报错了。很奇怪这个错误怎么产生的,老师有空可以解答一下吗?
132018-05-13 -
拾灬荒灬者
提问者
2018-05-05
public ServerResponse<CartVo> add(Integer userId,Integer productId,Integer count){
if(productId == null || count == null){
return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(),ResponseCode.ILLEGAL_ARGUMENT.getDesc());
}
Cart cart = cartMapper.selectCartByUserIdProductId(userId,productId);
if(cart == null){
//这个产品不在这个购物车里,需要新增一个这个产品的记录
Cart cartItem = new Cart();
cartItem.setQuantity(count);
cartItem.setChecked(Const.Cart.CHECKED);
cartItem.setProductId(productId);
cartItem.setUserId(userId);
cartMapper.insert(cartItem);
}else{
//这个产品已经在购物车里了.
//如果产品已存在,数量相加
count = cart.getQuantity() + count; —》这个是第53行
cart.setQuantity(count);
cartMapper.updateByPrimaryKeySelective(cart);
}
return this.list(userId);
}00 -
拾灬荒灬者
提问者
2018-05-05
@RequestMapping("add.do")
@ResponseBody
public ServerResponse<CartVo> add(HttpSession session, Integer count, Integer productId){
User user = (User)session.getAttribute(Const.CURRENT_USER);
if(user ==null){
return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),ResponseCode.NEED_LOGIN.getDesc());
}
return iCartService.add(user.getId(),productId,count); —>这个是第45行
}00
相似问题