您是要测试绑定(在调用此方法之前发生)还是要测试“提交”处理程序方法?
您可以使用以下方法测试绑定:
@Test public void testHandlerMethod() { final MockHttpServletRequest request = new MockHttpServletRequest("post", "/..."); request.setParameter("firstName", "Joe"); request.setParameter("lastName", "Smith"); final User user = new User(); final WebDataBinder binder = new WebDataBinder(user, "user"); binder.bind(new MutablePropertyValues(request.getParameterMap())); final ModelAndView mv = controllerTestInstance.submit(user, binder.getBindingResult()); // Asserts... }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)