|
@@ -1,19 +1,55 @@
|
|
|
package com.zskk.control;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.jfinal.core.Controller;
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
|
+import okhttp3.FormBody;
|
|
|
+import okhttp3.MediaType;
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
+import okhttp3.Request;
|
|
|
+import okhttp3.RequestBody;
|
|
|
+import okhttp3.Response;
|
|
|
+
|
|
|
public class ViewController extends Controller {
|
|
|
|
|
|
+ private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8");
|
|
|
+
|
|
|
+ private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
|
|
|
+
|
|
|
/**
|
|
|
* 在被连接数据库执行sql语句
|
|
|
*/
|
|
|
public void executeSql() {
|
|
|
- List<Record> d = Db.use("sx").find(this.getPara("sqlstr"));
|
|
|
+ List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
|
|
|
this.renderJson(d);
|
|
|
}
|
|
|
|
|
|
+ private static String doPost(String url, Map<String, String> map) throws IOException {
|
|
|
+ RequestBody formBody = new FormBody.Builder()
|
|
|
+ .add("key", "value")
|
|
|
+ .add("key", "value")
|
|
|
+ .build();
|
|
|
+
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(url)
|
|
|
+ .post(formBody)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
+ if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
|
|
+ System.out.println(response.body().string());
|
|
|
+ return response.body().string();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) throws IOException {
|
|
|
+ doPost("https://www.baidu.com", null);
|
|
|
+ }
|
|
|
}
|