2024年10月7日17:58:30
parent
0836533a13
commit
45863a24ed
|
|
@ -68,6 +68,8 @@ public class HomeController implements Serializable {
|
||||||
private AnchorPane spring_security;
|
private AnchorPane spring_security;
|
||||||
private AnchorPane jks_file;
|
private AnchorPane jks_file;
|
||||||
|
|
||||||
|
private AnchorPane user_password;
|
||||||
|
|
||||||
public static final String color_cell = "#f4f4f4";
|
public static final String color_cell = "#f4f4f4";
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|
@ -285,6 +287,13 @@ public class HomeController implements Serializable {
|
||||||
}
|
}
|
||||||
jks_file(flag);
|
jks_file(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newValue.getIndex() == 3) {
|
||||||
|
if (user_password != null){
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
user_password(flag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -294,6 +303,7 @@ public class HomeController implements Serializable {
|
||||||
case Md5 -> new Image(ImagePath.path(ImagePath.ImagePathType.MD5));
|
case Md5 -> new Image(ImagePath.path(ImagePath.ImagePathType.MD5));
|
||||||
case SpringSecurity -> new Image("image/spring.png");
|
case SpringSecurity -> new Image("image/spring.png");
|
||||||
case Jks_File -> new Image("image/jks.png");
|
case Jks_File -> new Image("image/jks.png");
|
||||||
|
case user_password -> new Image("image/jks.png");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -401,6 +411,23 @@ public class HomeController implements Serializable {
|
||||||
common_method();
|
common_method();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void user_password(boolean flag){
|
||||||
|
//默认选择第一个
|
||||||
|
listView.getSelectionModel().select(3);
|
||||||
|
|
||||||
|
if (!flag){
|
||||||
|
try {
|
||||||
|
root = FXMLLoader.load(ResourcesUtils.getResource("password"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
user_password = root;
|
||||||
|
}else {
|
||||||
|
root = user_password;
|
||||||
|
}
|
||||||
|
common_method();
|
||||||
|
}
|
||||||
|
|
||||||
private void common_method() {
|
private void common_method() {
|
||||||
splitPane.getItems().remove(1);
|
splitPane.getItems().remove(1);
|
||||||
splitPane.getItems().add(1, root);
|
splitPane.getItems().add(1, root);
|
||||||
|
|
@ -713,4 +740,9 @@ public class HomeController implements Serializable {
|
||||||
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
ListView<ResourcesUtils.Player> listView = (ListView) fx.lookup("#listView");
|
||||||
listView.getSelectionModel().select(index);
|
listView.getSelectionModel().select(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void user_password_item(ActionEvent actionEvent) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,219 @@
|
||||||
|
package com.zhangmeng.tools.controller;
|
||||||
|
|
||||||
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
import com.zhangmeng.tools.utils.AlertUtils;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class PasswordController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public Button save;
|
||||||
|
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public Button search;
|
||||||
|
|
||||||
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextField url;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextField username;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextField password;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextField remark;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
|
||||||
|
search.setOnAction(event -> {
|
||||||
|
|
||||||
|
if (url.getText().length() == 0 ){
|
||||||
|
AlertUtils.alert_warning("网址不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getJdbcTemplate();
|
||||||
|
|
||||||
|
queryDatabase(url.getText());
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
save.setOnAction(event -> {
|
||||||
|
|
||||||
|
if (username.getText().length() == 0 ){
|
||||||
|
AlertUtils.alert_warning("用户名不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (password.getText().length() == 0 ){
|
||||||
|
AlertUtils.alert_warning("密码不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.getText().length() == 0 ){
|
||||||
|
AlertUtils.alert_warning("网址不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (remark.getText().length() == 0 ){
|
||||||
|
AlertUtils.alert_warning("备注不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getJdbcTemplate();
|
||||||
|
List<UserInfo> userInfos = queryDatabase(url.getText(), false);
|
||||||
|
boolean flag= false;
|
||||||
|
if (userInfos != null && userInfos.size() > 0 ){
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
if (flag){
|
||||||
|
updateUserInfo(url.getText(),username.getText(),password.getText(),remark.getText());
|
||||||
|
}else {
|
||||||
|
saveUserInfo(username.getText(),password.getText(),url.getText(),remark.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String ip_address = "123.57.75.116";
|
||||||
|
private int port = 13306;
|
||||||
|
private String data_base = "user_password";
|
||||||
|
private String data_base_username = "root";
|
||||||
|
private String data_base_password = "root";
|
||||||
|
|
||||||
|
private JdbcTemplate getJdbcTemplate() {
|
||||||
|
if (jdbcTemplate == null) {
|
||||||
|
jdbcTemplate = new JdbcTemplate();
|
||||||
|
DruidDataSource datasource = new DruidDataSource();
|
||||||
|
String url = "jdbc:mysql://" + ip_address + ":" + port + "/" + data_base + "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true";
|
||||||
|
String driverClassName = "com.mysql.cj.jdbc.Driver";
|
||||||
|
datasource.setUrl(url);
|
||||||
|
datasource.setUsername(data_base_username);
|
||||||
|
datasource.setPassword(data_base_password);
|
||||||
|
datasource.setDriverClassName(driverClassName);
|
||||||
|
jdbcTemplate.setDataSource(datasource);
|
||||||
|
}
|
||||||
|
return jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void queryDatabase(String url) {
|
||||||
|
String sql = "SELECT * FROM user_info WHERE url = ?";
|
||||||
|
String urlToFind = "www.baidu.com"; // 你想查询的 URL
|
||||||
|
|
||||||
|
if (url != null ){
|
||||||
|
urlToFind = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserInfo> userInfoList = jdbcTemplate.query(sql, new Object[]{urlToFind}, new BeanPropertyRowMapper<>(UserInfo.class));
|
||||||
|
|
||||||
|
// 处理查询结果
|
||||||
|
// for (UserInfo userInfo : userInfoList) {
|
||||||
|
// System.out.println(userInfo);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (userInfoList.size() > 0 ){
|
||||||
|
UserInfo userInfo = userInfoList.get(0);
|
||||||
|
password.setText(userInfo.getPassword());
|
||||||
|
username.setText(userInfo.getUsername());
|
||||||
|
this.url.setText(userInfo.getUrl());
|
||||||
|
remark.setText(userInfo.getRemark());
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("userInfoList:" + userInfoList.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UserInfo> queryDatabase(String url,boolean flag) {
|
||||||
|
String sql = "SELECT * FROM user_info WHERE url = ?";
|
||||||
|
String urlToFind = "www.baidu.com"; // 你想查询的 URL
|
||||||
|
|
||||||
|
if (url != null ){
|
||||||
|
urlToFind = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<UserInfo> userInfoList = jdbcTemplate.query(sql, new Object[]{urlToFind}, new BeanPropertyRowMapper<>(UserInfo.class));
|
||||||
|
|
||||||
|
return userInfoList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveUserInfo(String username,String password,String url, String remark) {
|
||||||
|
String sql = "INSERT INTO user_info (username,password,url, remark) VALUES (?, ? , ? , ? )";
|
||||||
|
// 使用 jdbcTemplate.update 方法来执行插入操作
|
||||||
|
int result = jdbcTemplate.update(sql, username, password,url,remark);
|
||||||
|
if (result > 0) {
|
||||||
|
log.info("数据插入成功!");
|
||||||
|
AlertUtils.alert_msg("数据插入成功!");
|
||||||
|
} else {
|
||||||
|
log.info("数据插入失败!");
|
||||||
|
AlertUtils.alert_msg("数据插入失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateUserInfo(String url, String username, String password, String remark) {
|
||||||
|
|
||||||
|
String sql = "UPDATE user_info SET username = ?, password = ?, remark = ? WHERE url = ?";
|
||||||
|
|
||||||
|
// 使用 jdbcTemplate.update 方法来执行更新操作
|
||||||
|
int result = jdbcTemplate.update(sql, username, password, remark, url);
|
||||||
|
|
||||||
|
if (result > 0) {
|
||||||
|
log.info("数据更新成功!");
|
||||||
|
AlertUtils.alert_msg("数据更新成功!");
|
||||||
|
} else {
|
||||||
|
log.info("数据更新失败!");
|
||||||
|
AlertUtils.alert_msg("数据更新失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class UserInfo {
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRemark() {
|
||||||
|
return remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemark(String remark) {
|
||||||
|
this.remark = remark;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -51,6 +51,7 @@ public class ResourcesUtils {
|
||||||
Md5("md5加密", 0),
|
Md5("md5加密", 0),
|
||||||
SpringSecurity("spring加密", 1),
|
SpringSecurity("spring加密", 1),
|
||||||
Jks_File("Jks_File", 2),
|
Jks_File("Jks_File", 2),
|
||||||
|
user_password("user_info", 3),
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
<MenuItem mnemonicParsing="false" onAction="#md5_menu_item" text="md5 加密"/>
|
<MenuItem mnemonicParsing="false" onAction="#md5_menu_item" text="md5 加密"/>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#spring_security_menu_item" text="spring security 加密"/>
|
<MenuItem mnemonicParsing="false" onAction="#spring_security_menu_item" text="spring security 加密"/>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#jks_file_menu_item" text="jkd 文件生成"/>
|
<MenuItem mnemonicParsing="false" onAction="#jks_file_menu_item" text="jkd 文件生成"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#user_password_item" text="jkd 文件生成"/>
|
||||||
|
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?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.PasswordController">
|
||||||
|
<children>
|
||||||
|
<Label layoutX="447.0" layoutY="146.0" text="网站地址:" />
|
||||||
|
<Label layoutX="447.0" layoutY="234.0" text="用户名:" />
|
||||||
|
<Label layoutX="447.0" layoutY="309.0" text="密码:" />
|
||||||
|
<TextField fx:id="url" layoutX="508.0" layoutY="142.0" prefHeight="23.0" prefWidth="248.0" />
|
||||||
|
<TextField fx:id="username" layoutX="508.0" layoutY="230.0" prefHeight="23.0" prefWidth="248.0" />
|
||||||
|
<TextField fx:id="password" layoutX="508.0" layoutY="305.0" prefHeight="23.0" prefWidth="248.0" />
|
||||||
|
<TextField fx:id="remark" layoutX="508.0" layoutY="377.0" prefHeight="23.0" prefWidth="248.0" />
|
||||||
|
<Label layoutX="445.0" layoutY="381.0" text="备注:" />
|
||||||
|
<Button fx:id="save" layoutX="605.0" layoutY="460.0" mnemonicParsing="false" text="保存" AnchorPane.topAnchor="460.0" />
|
||||||
|
<Button fx:id="search" layoutX="774.0" layoutY="142.0" mnemonicParsing="false" text="查询" />
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
Loading…
Reference in New Issue