Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i notice that this controller has now been deprecated in the latest spring and was wondering what the alternative controller is?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
128 views
Welcome To Ask or Share your Answers For Others

1 Answer

In Spring 3.0 you should use simple classes annotated by @Controller. Such controller can handle more than one request. Each request is handled by its own method. These methods are annotated by @RequestMapping.

One thing you need to rethink is the fact, that a old school SimpleFormController handle a lot of different requests (at least: one to get the form and a second to submit the form). You have to handle this now by hand. But believe me it is easier.

For example this Controller in REST Style, will handle two requests:

  • /book - POST: to create a book
  • /book/form - GET: to get the form for creation

Java Code:

@RequestMapping("/book/**")
@Controller
public class BookController {

    @RequestMapping(value = "/book", method = RequestMethod.POST)
    public String create(
        @ModelAttribute("bookCommand") final BookCommand bookCommand) {

        Book book = createBookFromBookCommand(bookCommand);
        return "redirect:/book/" + book.getId();
    }

    @RequestMapping(value = "/book/form", method = RequestMethod.GET)
    public String createForm(final ModelMap modelMap) {
        modelMap.addAttribute("all", "what you need");
        return "book/create"; //book/create.jsp
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...