我遇到了一个问题,我在使用百日咳和Springboot的junit测试中遇到循环视图错误
我的测试如下使用路径变量:
@Test
public void testPostEditErrorsExit() throws Exception {
when(bindingResult.hasErrors()).thenReturn(true);
mockMvc.perform(post("/edit/{messageId}", 12345))
.andExpect(status().isOk()).andExpect(view().name("/messages/edit-message"));
}
控制器帖子如下:
@Controller
@RequestMapping("/edit")
public class UpdateController {
@PostMapping("/{messageId}")
public String postEditMessage(@PathVariable String messageId,
@ModelAttribute("siteMessage") @Valid SiteMessage siteMessage, BindingResult result, Model model,
RedirectAttributes attributes) {
String view;
if (result.hasErrors()) {
view = "/edit/" + messageId;
} else {}
return view;
}
}
错误是:Error rendering view [org.springframework.web.servlet.view.InternalResourceView: unnamed; URL [/edit/12345]] in DispatcherServlet with name ''
javax.servlet.ServletException: Circular view path [/edit/12345]: would dispatch back to the current handler URL [/edit/12345] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)