SPRINGMVC Test Controller Example

Example: Simulation/emps?pn=1Request; get the requested domain; get the request domain object; take the object from the request domain

@ RunWith (SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration (locations = { "classpath: applicationContext.xml", "classpath: springMVC.xml"}) public class TestList {@Autowired WebApplicationContext context; MockMvc mockMvc; @Before // Note that the packet is Junit public void initMockMvc () {mockMvc = MockMvcBuilders.webAppContextSetup (context) .build ();} @Test public void testList () throws Exception {// analog `/ emps pn = 1` request MvcResult result =? Mockmvc.Perform ("/ EMPS"). PARAM ("PN", "1")) .andReturn (); // Get request domain object mockhtpservletRequest request = Result.getRequest (); // From the request domain Medium value PageInfo PageInfo = (PageInfo); for (Object Employee: PageInfo.getlist ()) {system.out.println (Employee);}}}