Saturday, 8 April 2017

How to write simple Spring MVC or Spring Web Controller

Methods provided in the below class are some ways of mapping appropriate request to appropriate urls

@Controller
public class Controller {


 @RequestMapping(value = { "/url" }, method = {RequestMethod.GET,RequestMethod.POST})
 public String showPage(@Valid VO VO,
   BindingResult bindingResult, Locale locale, Model model, HttpSession session) {
   .
   .
   .
   .
 }

 @RequestMapping(value = "/url", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON)
 public @ResponseBody ResponseEntity<VO<vo>> searchByCriteria(
   @RequestBody @Valid FormVO formVO, BindingResult bindingResult, Model m,
   HttpServletRequest request) {
   .
   .
   .
 }

}

No comments:

Post a Comment