@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = {"classpath:applicationContext.xml","file:D:\workspace\ssmDemo\src\main\webapp\WEB-INF\dispatcherServlet-servlet.xml"})
public class MvcTest {
@Autowired
WebApplicationContext context;
//虚拟mvc请求,获取到处理结果
MockMvc mockMvc;
@Before
public void initMockMvc(){
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
}
@Test
public void testPage() throws Exception{
MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/emps").param("pn","1"))
.andReturn();
MockHttpServletRequest request = result.getRequest();
PageInfo pi= (PageInfo) request.getAttribute("pageInfo");
System.out.println("当前页码:"+pi.getPageNum());
System.out.println("总页码:"+pi.getPages());
System.out.println("总记录数:"+pi.getTotal());
System.out.println("在页面需要连续显示的页码");
int[] nums = pi.getNavigatepageNums();
for (int i : nums){
System.out.println(""+i);
}
List list = pi.getList();
for (Employee employee : list){
System.out.println("ID:"+employee.getEmpId()+"==>Name:"+employee.getEmpName());
}
}
}
空指针了呀,42行是什么内容呢,看下是什么为空了