httpclient 傳遞引數的問題
上次寫了httpclient 傳遞json的實現
具體主要使用@RequestBody 的註解 並且在請求是設定http傳參的的型別
json格式 如下
StringEntity stringEntity = new StringEntity(json字串,"UTF-8");//解決中文亂碼問題
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/json");
服務端引數接收:RemberBook 為實體類
@RequestMapping("/addRemberBook")
@ResponseBody
public ResultStatus addRemberBooks(@RequestBody RemberBook remberBook){
}
當使用@RequestParam 註解接收String 等型別的引數時
需要設定格式如下
StringEntity stringEntity = new StringEntity(“key=value&key1=value1”,"UTF-8");//解決中文亂碼問題
stringEntity.setContentEncoding("UTF-8");
stringEntity.setContentType("application/x-www-form-urlencoded");
服務端引數接收
@RequestMapping("/updateRemberBookStatus")
@ResponseBody
public ResultStatus updateRemberBookStatus(@RequestParam String account,@RequestParam String remid,@RequestParam String status ){
}