0

我正在尝试使用 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);
    }

我不确定我做错了什么。有人可以帮忙吗?

4

1 回答 1

2

我弄错了 CURL 语法。

我不应该尝试手动编码&符号。这就是问题的原因。

以下是发送 GET 请求的适当方式:

curl -i -X GET -H Accept:application/json "http://localhost:8080/kadjoukor/geolocations?findByPostcodeFirstChars&postcodeFirstChars=7500"

注意引号和 &

于 2012-10-23T19:14:38.213 回答