学习SSM框架分页插件查询时出现空指针异常,求解!!!

异常代码:

java.lang.NullPointerException
    at com.atguigu.crud.test.MvcTest.testPage(MvcTest.java:53)
    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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)

测试了一下:

    MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/emps").param("pn", "1")).andReturn();
        MockHttpServletRequest request = result.getRequest();

        System.out.println("1:"+request);

        System.out.println("2:"+request.getAttribute("pageInfo"));

结果:
1:org.springframework.mock.web.MockHttpServletRequest@4a067c25
2:null

是在执行了getAttribute()这个方法后出现的异常

代码检查了几遍了,不知道是不是哪个配置文件出了问题。


慕勒3428872
浏览 1373回答 2
2回答

月关宝盒

springmvc配置文件扫描设置有误
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java