请大神指点:可以得到页面数据id,但无法从数据库取出数据

一个人的工程 发布于 2016/12/19 11:32
阅读 983
收藏 0
DEBUG [http-apr-8080-exec-3] - Rendering view [org.springframework.web.servlet.view.JstlView: name 'items/itemsList'; URL [/WEB-INF/jsp/items/itemsList.jsp]] in DispatcherServlet with name 'springmvc'
DEBUG [http-apr-8080-exec-3] - Added model object 'itemsCustomList' of type [java.util.ArrayList] to request in view with name 'items/itemsList'
DEBUG [http-apr-8080-exec-3] - Forwarding to resource [/WEB-INF/jsp/items/itemsList.jsp] in InternalResourceView 'items/itemsList'
DEBUG [http-apr-8080-exec-3] - Successfully completed request
DEBUG [http-apr-8080-exec-3] - Returning cached instance of singleton bean 'sqlSessionFactory'
DEBUG [http-apr-8080-exec-4] - DispatcherServlet with name 'springmvc' processing GET request for [/ssm/items/editItems]
DEBUG [http-apr-8080-exec-4] - Looking up handler method for path /items/editItems
DEBUG [http-apr-8080-exec-4] - Returning handler method [public java.lang.String com.ssm.controller.ItemsController.editItems(org.springframework.ui.Model,java.lang.Integer) throws java.lang.Exception]
DEBUG [http-apr-8080-exec-4] - Returning cached instance of singleton bean 'itemsController'
DEBUG [http-apr-8080-exec-4] - Last-Modified value for [/ssm/items/editItems] is: -1
3
3
DEBUG [http-apr-8080-exec-4] - Should roll back transaction but cannot - no transaction available
DEBUG [http-apr-8080-exec-4] - Resolving exception from handler [public java.lang.String com.ssm.controller.ItemsController.editItems(org.springframework.ui.Model,java.lang.Integer) throws java.lang.Exception]: java.lang.NullPointerException
DEBUG [http-apr-8080-exec-4] - Resolving exception from handler [public java.lang.String com.ssm.controller.ItemsController.editItems(org.springframework.ui.Model,java.lang.Integer) throws java.lang.Exception]: java.lang.NullPointerException
DEBUG [http-apr-8080-exec-4] - Resolving exception from handler [public java.lang.String com.ssm.controller.ItemsController.editItems(org.springframework.ui.Model,java.lang.Integer) throws java.lang.Exception]: java.lang.NullPointerException
DEBUG [http-apr-8080-exec-4] - Could not complete request
java.lang.NullPointerException
at com.ssm.serviceImpl.ItemsServiceImpl.findItemById(ItemsServiceImpl.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at $Proxy11.findItemById(Unknown Source)
at com.ssm.controller.ItemsController.editItems(ItemsController.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:619)
2016-12-19 11:11:50 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [springmvc] in context with path [/ssm] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at com.ssm.serviceImpl.ItemsServiceImpl.findItemById(ItemsServiceImpl.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at $Proxy11.findItemById(Unknown Source)
at com.ssm.controller.ItemsController.editItems(ItemsController.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2517)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2506)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:619)

加载中
0
一个人的工程

谢谢,请大神审阅代码如下:

1、使用逆向工程生成的mapper

package com.ssm.mapper;


import com.ssm.po.Items;
import com.ssm.po.ItemsExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;


public interface ItemsMapper {
    int countByExample(ItemsExample example);


    int deleteByExample(ItemsExample example);


    int deleteByPrimaryKey(Integer id);


    int insert(Items record);


    int insertSelective(Items record);


    List<Items> selectByExampleWithBLOBs(ItemsExample example);


    List<Items> selectByExample(ItemsExample example);


    Items selectByPrimaryKey(Integer id);


    int updateByExampleSelective(@Param("record") Items record, @Param("example") ItemsExample example);


    int updateByExampleWithBLOBs(@Param("record") Items record, @Param("example") ItemsExample example);


    int updateByExample(@Param("record") Items record, @Param("example") ItemsExample example);


    int updateByPrimaryKeySelective(Items record);


    int updateByPrimaryKeyWithBLOBs(Items record);


    int updateByPrimaryKey(Items record);
}

2、itemsMapper的扩展类

ackage com.ssm.mapper;


import java.util.List;


import com.ssm.po.ItemsCustom;
import com.ssm.po.ItemsQueryVo;


public interface ItemsMapperCustom {




public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo) throws Exception;
}


3、service

package com.ssm.service;


import java.util.List;


import com.ssm.po.ItemsCustom;
import com.ssm.po.ItemsQueryVo;




public interface ItemsService {


public List<ItemsCustom> findItemsList(ItemsQueryVo itemsQueryVo) throws Exception;

//根据id查询商品信息,int类型不能校验为空,将id类型置为Integer类型
public ItemsCustom findItemById(Integer id) throws Exception;
//修改商品信息,将id作为参数从itemsCustom中提出取来。
public void updateItem(Integer id,ItemsCustom itemscustom) throws Exception;

}


4\service实现类

public class ItemsServiceImpl implements ItemsService {


@Autowired
private ItemsMapperCustom itemsMapperCustom;
private ItemsMapper itemsMapper;
private ItemsCustom itemsCustom;


public List<ItemsCustom> findItemsList(ItemsQueryVo  itemsQueryVo)
throws Exception {


return itemsMapperCustom.findItemsList(itemsQueryVo);
}



public ItemsCustom findItemById(Integer id) throws Exception {
System.err.println(id);


Items items = itemsMapper.selectByPrimaryKey(id);
//将items中的属性值拷贝到itemsCustom中;
System.out.println(items);
itemsCustom =new ItemsCustom();
BeanUtils.copyProperties(items, itemsCustom);
return itemsCustom;
}

5、controller

package com.ssm.controller;


import java.util.List;


import javax.servlet.http.HttpServletRequest;




import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;




import com.ssm.po.Items;
import com.ssm.po.ItemsCustom;
import com.ssm.service.ItemsService;
import com.ssm.serviceImpl.ItemsServiceImpl;


@Controller
@RequestMapping("/items")
public class ItemsController {


@Autowired
private ItemsService itemsService;
private ItemsCustom itemsCustom;





@RequestMapping("/queryItems")
public String queryItems(Model model ) throws Exception{
List<ItemsCustom> itemsCustomList = itemsService.findItemsList(null);
model.addAttribute("itemsCustomList", itemsCustomList);
return "items/itemsList";
}
//修改页面的展示
@RequestMapping("editItems")

public String editItems(Model model, Integer id) throws Exception{

System.out.println(id);

   itemsCustom = itemsService.findItemById(id);
   System.out.println(itemsCustom);
model.addAttribute("itemsCustom", itemsCustom);

return "items/itemsEdit";
}

0
G7
G7
没有注入ItemsServiceImpl
返回顶部
顶部