Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

What are the differences in these 2 controllers?

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello to all,

I am studing the Spring MVC showcase example downloaded from the STS dashboard.

I have a basic question for you:

In my home.jsp view I have two links, something like that:



So, in this example the first one is handled by a controller class named SimpleController and the second one is handled by a controller class named SimpleControllerRevisited

This is the code of SimpleController class:



As you can see the simple() method is annoted by @RequestMapping("/simple") annotation so it mean that this method handles request towards "/simple" folder. This method return a String to the caller and this string is encapsulated into the BODY section of the HTTP Response...ok it is very simple !!

Now this is the code of SimpleControllerRevisited



It is very similar to the previus SimpleController() method. It handles request towards "/simple/revisited" folder and return a string into the BODY of the HTTP Response

what is the difference between these two methods?

When I do:
method=RequestMethod.GET I'm specifying that the HTTP Request type is a GET...but is it not the default HTTP Request? Also in the other method is a GET although it is not explicitly specified? Or what?

What do exactly the: headers="Accept=text/plain" parameter of the @RequestMapping annotation?

thank you very much
Andrea




 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, the first one will also map tp POST, PUT and DELETE RequestMethodTypes. The second will only allow GET requests. For the second one the accept portion means the Request Header must have headers="Accept=text/plain" Otherwise that method will not be called regardless of URL or RequestMethod type.

Mark
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic