java - restful教學 - spring web service教學
如何在url請求中發送數組 (1)
用逗號分隔:
http://localhost:8080/MovieDB/GetJson?name=Actor1,Actor2,Actor3&startDate=20120101&endDate=20120505
要么:
http://localhost:8080/MovieDB/GetJson?name=Actor1&name=Actor2&name=Actor3&startDate=20120101&endDate=20120505
要么:
http://localhost:8080/MovieDB/GetJson?name[0]=Actor1&name[1]=Actor2&name[2]=Actor3&startDate=20120101&endDate=20120505
無論哪種方式,您的方法簽名都必須是:
@RequestMapping(value = "/GetJson", method = RequestMethod.GET)
public void getJson(@RequestParam("name") String[] ticker, @RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate) {
//code to get results from db for those params.
}
我的要求如下:
我想給演員姓名,開始日期,結束日期,並獲得他在那個時期演出的所有電影。
出於這個原因,我的服務請求是這樣的。
http://localhost:8080/MovieDB/GetJson?name=Actor&startDate=20120101&endDate=20120505
現在,我想改進它。 我想給出開始日期,結束日期和多個演員姓名,並希望在那段時間內看到所有演員電影。
我不確定我的網址應該如何支持這樣的事情。
我正在使用spring編寫基於Java的Web服務。
下面的代碼是支持一個actor
@RequestMapping(value = "/GetJson", method = RequestMethod.GET)
public void getJson(@RequestParam("name") String ticker, @RequestParam("startDate") String startDate, @RequestParam("endDate") String endDate) {
//code to get results from db for those params.
}
我想的一個解決方案是使用%符號來分隔演員姓名。 例如:
http://localhost:8080/MovieDB/GetJson?name=Actor1%Actor2%Actor3&startDate=20120101&endDate=20120505
現在,在控制器中,我將使用%解析名稱字符串並獲取所有actor名稱。
這是一個很好的方法嗎?還是有標準方法?
謝謝