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コマンドは、上記のメソッドではなく、常にこのメソッド(Roo ITDから)をGETします。

@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 に答える