添加上传工具 2023年3月8日10:16:37
parent
31e49d3fa6
commit
cbd00e53c6
|
|
@ -33,6 +33,7 @@ import javafx.beans.value.ChangeListener;
|
|||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.geometry.Pos;
|
||||
|
|
@ -403,4 +404,34 @@ public class HomeController implements Serializable {
|
|||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void http_request_menu_item(ActionEvent event) {
|
||||
load_http_tools(0);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void http_upload_menu_item(ActionEvent event) {
|
||||
load_http_tools(1);
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void http_download_menu_item(ActionEvent event) {
|
||||
load_http_tools(2);
|
||||
}
|
||||
|
||||
public void load_http_tools(int index) {
|
||||
AnchorPane fx = null;
|
||||
try {
|
||||
fx = FXMLLoader.load(ResourcesUtils.getResource("http-tools"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Scene scene = new Scene(fx);
|
||||
Stage stage = (Stage) splitPane.getScene().getWindow();
|
||||
stage.setScene(scene);
|
||||
|
||||
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||
listView.getSelectionModel().select(index);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package com.zhangmeng.tools.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-03-08 12:01
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpDownLoadController {
|
||||
}
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
package com.zhangmeng.tools.controller;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.zhangmeng.tools.utils.AlertUtils;
|
||||
import com.zhangmeng.tools.utils.HttpUtils;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.util.Callback;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-03-08 10:21
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpRequestController {
|
||||
|
||||
public enum Type{
|
||||
GET,
|
||||
POST;
|
||||
}
|
||||
|
||||
@FXML
|
||||
public Button commit;
|
||||
|
||||
@FXML
|
||||
public ListView<Data> request_params;
|
||||
|
||||
@FXML
|
||||
public TextField key;
|
||||
|
||||
@FXML
|
||||
public TextField value;
|
||||
|
||||
@FXML
|
||||
public Button add_params;
|
||||
|
||||
@FXML
|
||||
public TextField url;
|
||||
|
||||
@FXML
|
||||
public ComboBox<Type> request_type;
|
||||
|
||||
@FXML
|
||||
public TextArea request_result;
|
||||
|
||||
private ObservableList<Data> list = FXCollections.observableArrayList();
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
request_params.setFixedCellSize(40);
|
||||
request_params.setEditable(true);
|
||||
request_result.setWrapText(true);
|
||||
request_params.setCellFactory(new Callback<>() {
|
||||
@Override
|
||||
public ListCell<Data> call(ListView<Data> param) {
|
||||
return new ListCell<>(){
|
||||
@Override
|
||||
protected void updateItem(Data s, boolean b) {
|
||||
super.updateItem(s, b);
|
||||
if (!b){
|
||||
HBox hBox = new HBox();
|
||||
hBox.setAlignment(Pos.CENTER);
|
||||
hBox.getChildren().add(new Label(s.key + " <======> " + s.value));
|
||||
this.setGraphic(hBox);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
request_type.setItems(FXCollections.observableList(Arrays.stream(Type.values()).toList()));
|
||||
request_type.getSelectionModel().select(0);
|
||||
|
||||
request_params.setItems(list);
|
||||
|
||||
add_params.setOnAction(event -> {
|
||||
if (key.getText().length() == 0 ){
|
||||
AlertUtils.alert_warning("参数key不能为空!");
|
||||
return;
|
||||
}
|
||||
if (value.getText().length() == 0 ){
|
||||
AlertUtils.alert_warning("参数value不能为空!");
|
||||
return;
|
||||
}
|
||||
list.add(new Data(key.getText(),value.getText()));
|
||||
});
|
||||
|
||||
commit.setOnAction(event -> {
|
||||
|
||||
if (url.getText().length() == 0 ){
|
||||
AlertUtils.alert_warning("请求url不能为空!");
|
||||
return;
|
||||
}
|
||||
|
||||
Type type = request_type.getSelectionModel().getSelectedItem();
|
||||
|
||||
ObservableList<Data> items = request_params.getItems();
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
for (Data item : items) {
|
||||
map.put(item.key,item.value);
|
||||
}
|
||||
log.info("请求参数:{}",map);
|
||||
request_result.setText(null);
|
||||
if (type.equals(Type.GET)){
|
||||
if (map.entrySet().size()>0){
|
||||
request_result.setText(HttpUtils.get_request(url.getText(),map));
|
||||
}else {
|
||||
request_result.setText(HttpUtils.get_request(url.getText()));
|
||||
}
|
||||
}
|
||||
if (type.equals(Type.POST)){
|
||||
if (map.entrySet().size()>0){
|
||||
request_result.setText(HttpUtils.post_request(url.getText(),map));
|
||||
}else {
|
||||
request_result.setText(HttpUtils.post_request(url.getText(),null));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static class Data{
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public Data(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.zhangmeng.tools.controller;
|
||||
|
||||
import com.zhangmeng.tools.utils.ImagePath;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TextArea;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-03-08 12:00
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpUploadController {
|
||||
|
||||
@FXML
|
||||
public Button upload_button;
|
||||
|
||||
@FXML
|
||||
public TextArea upload_result;
|
||||
|
||||
@FXML
|
||||
public TextField url;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
upload_button.setText(null);
|
||||
ImageView iv = new ImageView(new Image(ImagePath.path(ImagePath.ImagePathType.IMAGE_FILE)));
|
||||
iv.setPreserveRatio(true);
|
||||
iv.setFitWidth(18);
|
||||
upload_button.setGraphic(iv);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.zhangmeng.tools.utils;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author : 芊芊墨客
|
||||
* @version : 1.0
|
||||
* @date : 2023-03-08 10:41
|
||||
*/
|
||||
@Slf4j
|
||||
public class HttpUtils {
|
||||
|
||||
public static String get_request(String url){
|
||||
return HttpRequest.get(url).execute().body();
|
||||
}
|
||||
public static String get_request(String url, Map<String,Object> paramMap){
|
||||
return HttpRequest.get(url).form(paramMap).execute().body();
|
||||
}
|
||||
public static String get_request(String url,Map<String,Object> paramMap, Charset charset){
|
||||
return HttpRequest.get(url).form(paramMap).charset(charset).execute().body();
|
||||
}
|
||||
|
||||
public static String get_request(String url,Map<String,Object> paramMap, Charset charset,int milliseconds ){
|
||||
return HttpRequest.get(url).form(paramMap).charset(charset).timeout(milliseconds).execute().body();
|
||||
}
|
||||
|
||||
public static String post_request(String url,Map<String,Object> paramMap){
|
||||
return HttpUtil.post(url, paramMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -55,9 +55,11 @@
|
|||
</items>
|
||||
</Menu>
|
||||
|
||||
<Menu mnemonicParsing="false" text="network工具">
|
||||
<Menu mnemonicParsing="false" text="http工具">
|
||||
<items>
|
||||
<MenuItem mnemonicParsing="false" text="netty-websocket工具" onAction="#netty_client_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="http请求工具" onAction="#http_request_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="http上传工具" onAction="#http_upload_menu_item"/>
|
||||
<MenuItem mnemonicParsing="false" text="http下载工具" onAction="#http_download_menu_item"/>
|
||||
</items>
|
||||
</Menu>
|
||||
</menus>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,28 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="fxml.HttpRequest"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ComboBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.TextArea?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<AnchorPane prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.HttpRequestController">
|
||||
<children>
|
||||
<Label layoutX="125.0" layoutY="57.0" text="请求的url:" />
|
||||
<TextField fx:id="url" layoutX="207.0" layoutY="53.0" prefHeight="25.0" prefWidth="888.0" AnchorPane.leftAnchor="207.0" AnchorPane.rightAnchor="105.0" />
|
||||
<Label layoutX="129.0" layoutY="99.0" text="请求方式:" />
|
||||
<ComboBox fx:id="request_type" layoutX="207.0" layoutY="95.0" prefWidth="150.0" />
|
||||
<Label layoutX="127.0" layoutY="269.0" text="请求结果:" />
|
||||
<TextArea fx:id="request_result" layoutX="207.0" layoutY="269.0" prefHeight="200.0" prefWidth="888.0" AnchorPane.bottomAnchor="180.0" AnchorPane.leftAnchor="207.0" AnchorPane.rightAnchor="105.0" AnchorPane.topAnchor="269.0" />
|
||||
<Button fx:id="commit" layoutX="624.0" layoutY="493.0" mnemonicParsing="false" text="提交" AnchorPane.bottomAnchor="131.0" />
|
||||
<Label layoutX="127.0" layoutY="140.0" text="请求参数:" />
|
||||
<ListView fx:id="request_params" layoutX="207.0" layoutY="140.0" prefHeight="108.0" prefWidth="299.0" />
|
||||
<Label layoutX="569.0" layoutY="99.0" text="请求参数key:" />
|
||||
<Label layoutX="841.0" layoutY="99.0" text="请求参数value:" />
|
||||
<TextField fx:id="key" layoutX="651.0" layoutY="95.0" />
|
||||
<TextField fx:id="value" layoutX="934.0" layoutY="95.0" />
|
||||
<Button fx:id="add_params" layoutX="785.0" layoutY="169.0" mnemonicParsing="false" text="添加参数" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TextArea?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
|
||||
<AnchorPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="fxml.HttpUpload"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
|
||||
<AnchorPane prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.HttpUploadController">
|
||||
<children>
|
||||
<Label layoutX="190.0" layoutY="157.0" text="选择文件:" />
|
||||
<Button fx:id="upload_button" layoutX="306.0" layoutY="153.0" mnemonicParsing="false" text="Button" />
|
||||
<TextArea fx:id="upload_result" layoutX="306.0" layoutY="274.0" prefHeight="200.0" prefWidth="776.0" AnchorPane.bottomAnchor="175.0" AnchorPane.leftAnchor="306.0" AnchorPane.rightAnchor="118.0" AnchorPane.topAnchor="274.0" />
|
||||
<Label layoutX="190.0" layoutY="266.0" text="上传结果:" />
|
||||
<Label layoutX="190.0" layoutY="85.0" text="上传接口:" />
|
||||
<TextField fx:id="url" layoutX="306.0" layoutY="81.0" prefHeight="25.0" prefWidth="776.0" AnchorPane.leftAnchor="306.0" AnchorPane.rightAnchor="118.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
|
|
|||
Loading…
Reference in New Issue