http 工具类
parent
cb3f90eafb
commit
85c9eff53e
21
pom.xml
21
pom.xml
|
|
@ -40,25 +40,16 @@
|
|||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>de.jensd</groupId>
|
||||
<artifactId>fontawesomefx-commons</artifactId>
|
||||
<version>11.0</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.8.22</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.jensd</groupId>
|
||||
<artifactId>fontawesomefx-fontawesome</artifactId>
|
||||
<version>4.7.0-11</version>
|
||||
<scope>compile</scope>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.83</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.controlsfx</groupId>
|
||||
<artifactId>controlsfx</artifactId>
|
||||
<version>11.2.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package com.zhangmeng.online.exam.ui.utils;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zm
|
||||
* @date 2025/3/5 15:28
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class HttpUtils<T> {
|
||||
|
||||
public static <T> T GET(String url, Class<T> clazz) {
|
||||
String response = HttpUtil.get(url, CharsetUtil.CHARSET_UTF_8);
|
||||
return JSONObject.parseObject(response, clazz);
|
||||
}
|
||||
|
||||
public static <T> T GET(String url, Map<String, Object> params, Class<T> clazz) {
|
||||
String response = HttpUtil.get(url, params);
|
||||
return JSONObject.parseObject(response, clazz);
|
||||
}
|
||||
|
||||
public static <T> T POST(String url, Map<String, Object> params, Class<T> clazz) {
|
||||
String response = HttpUtil.post(url, params);
|
||||
return JSONObject.parseObject(response, clazz);
|
||||
}
|
||||
|
||||
public static <T> T POSTFileUPLOAD(String url, Map<String, Object> params, File file, Class<T> clazz) {
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
//文件上传只需将参数中的键指定(默认file),值设为文件对象即可,对于使用者来说,文件上传与普通表单提交并无区别
|
||||
paramMap.put("file", file);
|
||||
paramMap.putAll(params);
|
||||
String response = HttpUtil.post(url, paramMap);
|
||||
return JSONObject.parseObject(response, clazz);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
module com.zhangmeng.onlineexamui {
|
||||
requires javafx.controls;
|
||||
requires javafx.fxml;
|
||||
requires cn.hutool;
|
||||
requires java.sql;
|
||||
requires fastjson;
|
||||
|
||||
|
||||
opens com.zhangmeng.online.exam.ui to javafx.fxml;
|
||||
|
|
|
|||
Loading…
Reference in New Issue