Affiliate Marketing
Pls Subscribe this channel Subscribe ® Registered teknosys.in
Now you are ready to return JSON response from your MVC controller. All you have to do is return JAXB annotated object from method and usecom.fasterxml.jackson.core jackson-databind 2.4.1
@ResponseBody annotation on this return type.@Controller
public class EmployeeRESTController
{
@RequestMapping(value = "/employees")
public @ResponseBody EmployeeListVO getAllEmployees()
{
EmployeeListVO employees = new EmployeeListVO();
//Add employees
return employees;
}
}
Alternatively, you can use @RestController annotation in place of @Controller annotation. This will remove the need to using @ResponseBody.@RestController = @Controller + @ResponseBodySo you can write the above controller as below.
@RestController
public class EmployeeRESTController
{
@RequestMapping(value = "/employees")
public EmployeeListVO getAllEmployees()
{
EmployeeListVO employees = new EmployeeListVO();
//Add employees
return employees;
}
}
Comments