我正在尝试使用 CURL 获取以下方法:
@RooWebJson(jsonObject = Geolocation.class)
@Controller
@RequestMapping("/geolocations")
public class GeolocationController {
@Autowired
private GeolocationRepository geolocationRepository;
@RequestMapping(params = "findByPostcodeFirstChars", method = RequestMethod.GET, headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<String> jsonFindGeolocationsByPostcodeFirstChars(@RequestParam("postcodeFirstChars") String postcodeFirstChars) {
System.out.println("jsonFindGeolocationsByPostcodeFirstChars");
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
List<Geolocation> geolocations = geolocationRepository.findByPostcodeStartingWith(postcodeFirstChars);
return new ResponseEntity<String>(Geolocation.toJsonArray(geolocations), headers, HttpStatus.OK);
}
}
我使用 CURL 如下:
curl -i -H Accept:application/json http://localhost:8080/kadjoukor/geolocations?findByPostcodeFirstChars%26postcodeFirstChars=7500
但是,上面的 CURL 命令总是 GET 这个方法(来自 Roo ITD)而不是上面的:
@RequestMapping(headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<String> GeolocationController.listJson() {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
List<Geolocation> result = geolocationRepository.findAll();
return new ResponseEntity<String>(Geolocation.toJsonArray(result), headers, HttpStatus.OK);
}
我不确定我做错了什么。有人可以帮忙吗?