@RequestMapping("/userinfo")
public String getUserInfo(HttpServletRequest request, HttpServletResponse response) {
String id=request.getParameter("id");
if(id==null)return "{\"responseCode\":\"1000\"}" ;
String body= null;
try {
body = UserUtils.getUserInfo(id).toString();
} catch (Exception throwables) {
return "{\"responseCode\":\"1000\"}";
}
return body;
}
public static Map<String,Object> getUserInfo(String id) throws SQLException {
QueryRunner qr = new QueryRunner(C3p0Utils.getDataSoruce());
String sql = "select * from test_login where id = ?";
return qr.query(sql, new MapHandler(), id);
}
try {
URL url = new URL("http://localhost:8080/userinfo?id=1");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setUseCaches(false);
conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
StringBuilder sb = new StringBuilder();
String postinfor = "";
while ((postinfor = reader.readLine()) != null) {
sb.append(postinfor + "\n");
}
reader.close();
conn.disconnect();
System.out.println("接收到了信息:" + sb.toString());
}catch (Exception e){
e.printStackTrace();
}