मैंने एक साधारण आरईएसटी सेवा (POST) बनाई है। लेकिन जब मैं इस सेवा को डाकिया @RequestBody से कॉल करता हूं तो कोई मूल्य नहीं प्राप्त होता है।@RequestBody को शून्य मान मिल रहे हैं
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
@RestController
public class Add_Policy {
@ResponseBody
@RequestMapping(value = "/Add_Policy", headers = {
"content-type=application/json" }, consumes = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
public Policy GetIPCountry(@RequestBody Policy policy) {
System.out.println("Check value: " + policy.getPolicyNumber());
return policy;
}
}
मेरे जावा बीन वस्तु नीचे की तरह है:
public class Policy {
private String PolicyNumber;
private String Type;
private String Tenture;
private String SDate;
private String HName;
private String Age;
public String getPolicyNumber() {
return PolicyNumber;
}
public void setPolicyNumber(String policyNumber) {
PolicyNumber = policyNumber;
}
public String getType() {
return Type;
}
public void setType(String type) {
Type = type;
}
public String getTenture() {
return Tenture;
}
System.out.println PolicyNumber के मान की जगह एक अशक्त प्रिंट कर रहा है।
कृपया इस समस्या को हल करने में मेरी मदद करें।
JSON जो मैं अनुरोध शरीर में गुजर रहा
{
"PolicyNumber": "123",
"Type": "Test",
"Tenture": "10",
"SDate": "10-July-2016",
"HName": "Test User",
"Age": "10"
}
मैं भी डाकिया में application/json
को Content-Type
निर्धारित किया है
विधि के आउटपुट के लिए विधि @ @ ResponseBody' लागू करें विधि नहीं। यदि आप JSON मान की अपेक्षा कर रहे हैं तो 'उत्पाद' शीर्षलेख मान भी शामिल करें। – 11thdimension
भले ही मैं शून्य के रूप में प्रतिक्रिया करता हूं, अनुरोध से मूल्य समान शून्य है – Geek
'नीति' स्वयं शून्य नहीं था, क्या आप वाकई 'policyNumber'' हैं? – 11thdimension