Tag: 请求映射的

在Spring中结合GET和POST请求方法

我有一个支持GET和POST请求的资源。 这里是一个示例资源的示例代码: @RequestMapping(value = "/books", method = RequestMethod.GET) public ModelAndView listBooks(@ModelAttribute("booksFilter") BooksFilter filter, two @RequestParam parameters, HttpServletRequest request) throws ParseException { LONG CODE } @RequestMapping(value = "/books", method = RequestMethod.POST) public ModelAndView listBooksPOST(@ModelAttribute("booksFilter") BooksFilter filter, BindingResult result) throws ParseException { SAME LONG CODE with a minor difference } 这两个方法中的代码实际上是相同的,除了让我们说一个variables的定义。 这两个方法可以很容易地使用method = {RequestMethod.POST, RequestMethod.GET}和一个简单的if里面。 我尝试了,但它不起作用,因为这两个方法在最后有不同的参数,即HttpServletRequest和BindingResult ( […]