Questions tagged «spring-mvc-test»

20
Spring MVC测试中如何避免“圆形视图路径”异常
我的一个控制器中有以下代码: @Controller @RequestMapping("/preference") public class PreferenceController { @RequestMapping(method = RequestMethod.GET, produces = "text/html") public String preference() { return "preference"; } } 我只是想使用Spring MVC测试来测试它,如下所示: @ContextConfiguration @WebAppConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class PreferenceControllerTest { @Autowired private WebApplicationContext ctx; private MockMvc mockMvc; @Before public void setup() { mockMvc = webAppContextSetup(ctx).build(); } @Test public void circularViewPathIssue() …

3
模拟MVC-添加请求参数进行测试
我正在使用Spring 3.2模拟MVC测试我的控制器。我的代码是 @Autowired private Client client; @RequestMapping(value = "/user", method = RequestMethod.GET) public String initUserSearchForm(ModelMap modelMap) { User user = new User(); modelMap.addAttribute("User", user); return "user"; } @RequestMapping(value = "/byName", method = RequestMethod.GET) @ResponseStatus(HttpStatus.OK) public @ResponseBody String getUserByName( @RequestParam("firstName") String firstName, @RequestParam("lastName") String lastName, @ModelAttribute("userClientObject") UserClient userClient) { return client.getUserByName(userClient, …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.