81,094
社区成员
发帖
与我相关
我的任务
分享
public static void submitPost2(String url) {
HttpClient client = HttpClients. createDefault();
HttpPost post = new HttpPost(url);
JSONObject json = new JSONObject();
json.put("id",1);
try {
post.addHeader("Content-type", "application/json; charset=utf-8");
post.setHeader("Accept", "application/json");
post.setEntity(new StringEntity(json.toString(), Charset.forName("UTF-8")));
HttpResponse httpResponse = client.execute(post);
HttpEntity entity = httpResponse.getEntity();
System.out.println("status:" + httpResponse.getStatusLine());
System.out.println("response content:" + EntityUtils.toString(entity));
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
@Controller
@RequestMapping("/clients")
public class ClientsController {
@Autowired
private MonitorClientService monitorClientService;
@RequestMapping(value = "/getClientList",method = RequestMethod.POST)
@ResponseBody
public List<MonitorClient> getClientList(){
return monitorClientService.getAllClients();
}
@RequestMapping(value = "/addClient",method = RequestMethod.POST)
@ResponseBody
public int addClient(MonitorClient monitorClient){
return monitorClientService.addClient(monitorClient);
}
@RequestMapping(value = "/getClient",method = RequestMethod.POST)
@ResponseBody
public MonitorClient getMonitorClientById(Integer id){
return monitorClientService.getMonitorById(id);
}
@RequestMapping(value = "/updateClient",method = RequestMethod.POST)
@ResponseBody
public int updateClient(MonitorClient monitorClient){
return monitorClientService.updateMonitor(monitorClient);
}
}