我正在为SpringMvc应用编写测试,但我遇到了一些问题。
这是我的测试控制器方法:
@RequestMapping(value = "submit", method = RequestMethod.POST, params = "delete")
public String delete(@ModelAttribute("inputBean") InputBean inputBean) {
Book book = (Book) itemServiceController.getItemFindByIdService().findById(inputBean.getId());
Author author = getAuthorOfBook(book);
author.getBookList().remove(book);
authorServiceController.getAuthorCreateService().create(authorServiceController.getAuthorUpdateService().update(author));
itemServiceController.getItemDeleteService().delete(inputBean.getId());
return "redirect:index.html";
}
这是我的mockMvc:
mockMvc.perform(post("/submit?delete")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.param("id", "1")
.sessionAttr("inputBean", new InputBean())
)
.andExpect(status().isOk())
.andExpect(view().name("indexLib"))
.andExpect(model().attribute("inputBean", hasProperty("id", is(1))));
返回状态http状态400。
控制器方法用于4个表单提交按钮中的1个。如何解决这个问题?
答案 0 :(得分:0)
我找到了答案,正确的网址应该是
"/submit?id=102&delete="