Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Spring
Search Coderanch
Advance search
Google search
Register / Login
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:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Liutauras Vilda
Paul Clapham
Sheriffs:
paul wheaton
Tim Cooke
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Piet Souris
Bartenders:
Mike London
Forum:
Spring
what is the best way of defining methods in controller class of spring
somashaker goud
Ranch Hand
Posts: 64
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Below is my controller class code where i got confused on what is best way of returning from methods (
String
or object of modelandView) and how view resolver will interpret if we return string or modelview object
package com.soma.spring.mvc; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; @Controller public class HelloWorldController { @RequestMapping("/") public String hello() { return "hello"; } @RequestMapping(value = "/hi", method = RequestMethod.POST) public String hi(@RequestParam("name") String name, Model model) { String message = "Hi " + name + "!"; model.addAttribute("message", message); return "hi"; } @RequestMapping("/helloNew") public ModelAndView helloWorld() { String message = "HELLO SPRING MVC HOW R U"; return new ModelAndView("hi", "message", message); } }
Tushar Goel
Ranch Hand
Posts: 954
4
posted 5 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
if view is involved then ModelAndView is good option. Otherwise you can use ResponseEntity to return the object
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
issuer with internationalization
org.springframework.web.servlet.DispatcherServlet noHandlerFound
HTTP Status 404 - The requested resource is not available.
Redirect to .jsp Spring MVC
Use of redirect: in Spring MVC
More...