I have two mapera

@RequestMapping(value = "/", method = RequestMethod.GET) public String main(){ return "index"; } 

and second

 @RequestMapping(value = "/search", method = RequestMethod.GET) public String search(Model model , @RequestParam(value = "text",required = true)String text) { List<Book> books = bookMapper.findByCondition(text); return "redirect:/"; } 

how to transfer List<Book> books to the first controller

  • And what will be done with this list? Will it just be displayed as a result or will it have some kind of processing? - Alexander Ozertsov
  • So far, only output to the page - Farhad Kurbanov

1 answer 1

When a request is redirected using

 return "redirect:/" 

then a new request is created and all the attributes of the previous request are not transmitted, although you can pass attributes if you use RedirectAttributes .

The easiest way is to pass in the same request.

 @RequestMapping(value = "/search", method = RequestMethod.GET) public String search(Model model , @RequestParam(value = "text",required = true)String text) { List<Book> books = bookMapper.findByCondition(text); model.addAttribute("books", books); return "forward:/"; } 
  • didn’t quite understand, didn’t understand exactly - Farhad Kurbanov
  • Now I hope it became clear? - Roman C
  • I understand, thanks, but how about redirect, do you know where to read about it - Farhad Kurbanov
  • Under the link there is an example - Roman C