Tutorial :Spring MVC Web PetClinic Tutorial?



Question:

Is there a tutorial that goes along with the PetClinic application? I have been trying to find one, but google is not helping me today. Specifically, I dont understand things like:

@Autowired - what does that even mean?

@RequestMapping(method = RequestMethod.GET)  public String setupForm(@RequestParam("petId") int petId, ModelMap model) {      Pet pet = this.clinic.loadPet(petId);      model.addAttribute("pet", pet);      return "petForm";  }  

How can a request return just a string? Shouldnt it need to return some sort of ModelAndView? Or does the application somehow redirect to whatever is returned?

A lot of confusing concepts - if there is a tutorial, or video (like spring-security has) that would be very helpful. Thanks.


Solution:1

Autowired is Dependency injection. It creates beans for you and sets them.

In this example the controller is returning a String that is the name of the view. It's basically the same thing as

return new ModelAndView("petForm");   

It could map to something else or it could be as simple as returning petForm.jsp. Depends on the View Resolver.


Solution:2

It is returning the exact name of the view, so you could expect this to redirect you to the view located at /WEB-INF/jsp/petForm.jsp which will have access to the pet model


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »