This is one of the example I have created:-
/********This is controller getMethod**********/
@RequestMapping(value = "/employee/{id}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE,MediaType.APPLICATION_XML_VALUE})
public ResponseEntity<Employee> getEmployee(@PathVariable("id") long id) {
System.out.println("Fetching Employee with id " + id);
Employee user = employeeService.findById(id);
if (user == null) {
System.out.println("Employee with id " + id + " not found");
return new ResponseEntity<Employee>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<Employee>(user, HttpStatus.OK);
}
/********This is client implementation**********/
@RequestMapping(value = "/employee/{id}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE,MediaType.APPLICATION_XML_VALUE})
public ResponseEntity<Employee> getEmployee(@PathVariable("id") long id) {
System.out.println("Fetching Employee with id " + id);
Employee user = employeeService.findById(id);
if (user == null) {
System.out.println("Employee with id " + id + " not found");
return new ResponseEntity<Employee>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<Employee>(user, HttpStatus.OK);
}
/*************Done**************/
/*******Output******/
<200 OK,<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<employee>
<age>33</age>
<id>1</id>
<name>Tomy</name>
<salary>70000.0</salary>
</employee>`enter code here`
,{Server=[Apache-Coyote/1.1], Access-Control-Allow-Origin=[*], Access-Control-Allow-Methods=[POST, GET, PUT, OPTIONS, DELETE], Access-Control-Max-Age=[3600], Access-Control-Allow-Headers=[x-requested-with], Content-Type=[application/xml], Transfer-Encoding=[chunked], Date=[Wed, 20 Apr 2016 12:49:16 GMT]}>
HttpEntityエンティティ=新しいHttpEntity (ボディ、ヘッダ);この行には何がありますか? –
priyanka
リクエストの本文。必須ではない場合は(ヘッダーが必要な場合)空のままにしておくことができます –
よかったです。 – priyanka