Spring SimpleFormController in 3.0?

In Spring 3.0 you should use simple classes annotated by Controller . Such controller can handle more than one request. Each request is handles by its own method.

This methods are annotated by RequestMapping .

Up vote 1 down vote favorite 1 share g+ share fb share tw.

Thanks in advance java spring spring-mvc link|improve this question edited Jan 19 '11 at 10:41Sean Patrick Floyd54.8k539113 asked Jan 19 '11 at 10:38jonney712933 51% accept rate.

Bear in mind that wile the deprecated stuff still works in Spring 3, the Spring guys are much more aggressive in removing deprecated APIs than the JavaSE people, i. E they actually will remove them. – skaffman Jan 19 '11 at 11:01.

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

This methods are annotated by @RequestMapping. On think you need to rethink is the fact, that a old school SimpleFormController handle a lot of different requests (min: one to get the form and a second to submit the form). You have to handle this now by hand.

But belive me it is eayser. 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 EtfController { @RequestMapping(value = "/book", method = RequestMethod. POST) public String create( @ModelAttribute("bookCommand") final BookCommand bookCommand) { if (bookCommand == null) { throw new IllegalArgumentException("A bookDt is required"); } 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 } }.

Cheers. Annotaing mapping is all new to me as I was following this book I got amazon.co. Uk/Spring-Action-Craig-Walls/dp/1933988134/… – jonney Jan 19 '11 at 14:39 quick question.

Does that mean I no longer have to map my controllers into beans via xml files? – jonney Jan 19 '11 at 15:17 @jonney: Yes, there are new Annotations: @Controller, @Service, @Repository, as well as @Autowire and @Inject. But you have to enable something that is called component scan in your xml.

- Have a look at the SpringSource blog (around end of 2009) and the new features section of the Spring reference. -- You are also free to ask a new question. – Ralph Jan 19 '11 at 15:30 awsome.

This way is definitely easier! I'l have a look at the other annotations in spring. – jonney Jan 19 '11 at 15:59.

Annotated POJOs can act as controllers; see @Controller.

Grr, you were first :-) – Sean Patrick Floyd Jan 19 '11 at 10:43.

In Spring 3.0, your Controllers should no longer inherit from a base class. The standard way is to use annotated controllers.

– jonney Jan 19 '11 at 15:29 @jonney exactly. The XML way to do it is not even documented anymore in the Spring 3 Reference. – Sean Patrick Floyd Jan 19 '11 at 15:33 what about for DI and aspects?

All can be defined using annotations now? Is there any need to write any spring bean anymore lol? – jonney Jan 20 '11 at 9:40 @jonney there are ApplicationContext implementations that don't need XML at all, e.g. AnnotationConfigApplicationContext.

But usually, some XML is required (and with Springsource Tool Suite, managing the XML is actually fun) – Sean Patrick Floyd Jan 20 '11 at 9:48.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions