Wednesday, 8 July 2015

Spring rest json responce

1) Create bean of JSON view resolver

<bean name="jsonTemplate" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>

2) Return this Json view from modelAndView controller

@RequestMapping(value = "/clients")
public String getAllClientsJSON(Model model) {

model.addAttribute("clients", getClientsCollection());
 return "jsonTemplate";

 }

//getClientsCollection() this meothod will have list of clients

No comments:

Post a Comment