下面来介绍创建maven的javaFX+springboot项目,基于用户界面与后天逻辑分离的方式,用户界面使用fxml文件来常见,类似于jsp,可以引入css文件修饰界面

maven依赖

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>de.roskenet</groupId>
<artifactId>springboot-javafx-support</artifactId>
<version>${springboot-javafx-support.version}</version>
</dependency>
  • 创建login.fxml文件,将文件放入resources下,因为springboot默认加载的资源为resources
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?> <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
prefHeight="588.0" prefWidth="802.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"
fx:controller="com.dome.controller.LoginController">
<children>
<HBox layoutX="122.0" layoutY="108.0" prefHeight="372.0" prefWidth="526.0">
<children>
<Label alignment="CENTER" contentDisplay="CENTER" prefHeight="30.0" prefWidth="70.0" text="用户名" textAlignment="LEFT">
<font>
<Font size="18.0" fx:id="x1" />
</font>
<HBox.margin>
<Insets bottom="10.0" left="50.0" right="10.0" top="100.0" />
</HBox.margin>
</Label>
<TextField fx:id="userName" id="username" prefHeight="30.0" prefWidth="200.0">
<HBox.margin>
<Insets bottom="10.0" right="10.0" top="100.0" />
</HBox.margin>
</TextField>
<Label alignment="CENTER" contentDisplay="CENTER" font="$x1" prefHeight="30.0" prefWidth="70.0" text="密 码" textAlignment="LEFT">
<HBox.margin>
<Insets bottom="10.0" left="-290.0" top="140.0" />
</HBox.margin>
</Label>
<TextField fx:id="passWord" id="password" prefHeight="30.0" prefWidth="200.0">
<HBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="140.0" />
</HBox.margin>
</TextField>
<Button id="region" contentDisplay="CENTER" font="$x1" minHeight="28.0" mnemonicParsing="false" opacity="0.79" prefHeight="35.0" prefWidth="75.0" text="注册" textAlignment="CENTER">
<HBox.margin>
<Insets bottom="10.0" left="-240.0" top="200.0" />
</HBox.margin>
</Button>
<Button id="login" font="$x1" minHeight="28.0" mnemonicParsing="false" opacity="0.79" prefHeight="35.0" prefWidth="75.0"
text="登录" onAction="#btnClick" >
<HBox.margin>
<Insets bottom="10.0" left="60.0" top="200.0" />
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</AnchorPane>
  • 创建LoginFXML类,指定fxml文件的路径,及引入fxml文件所需的样式
import de.felixroske.jfxsupport.AbstractFxmlView;
import de.felixroske.jfxsupport.FXMLView; @FXMLView(value = "/static/fxml/login.fxml", css = {"/static/style/login.css"},title = "用户登录")
public class LoginFXML extends AbstractFxmlView { }

可以来了解下FXMLView的参数

@Component
@Retention(RetentionPolicy.RUNTIME)
public @interface FXMLView {
String value() default ""; String[] css() default {}; String bundle() default ""; String title() default ""; String stageStyle() default "UTILITY";
}
  • 创建LoginController,与用户界面进行交互
import com.dome.MainController;
import com.dome.domain.Student;
import com.dome.service.IStudentService;
import com.dome.view.LoginFXML;
import de.felixroske.jfxsupport.FXMLController;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import org.springframework.beans.factory.annotation.Autowired; import java.net.URL;
import java.util.List;
import java.util.ResourceBundle; @FXMLController
public class LoginController implements Initializable { @FXML
private Button button;
@FXML
private TextField userName; @Autowired
private IStudentService studentService; private ResourceBundle resourceBundle; @Override
public void initialize(URL location, ResourceBundle resources) {
resourceBundle = resources;
} @FXML
public void btnClick(ActionEvent actionEvent) {
List<Student> students = studentService.listAll();
userName.setText("helloWorld");
} @FXML
public void btnLoginClick(ActionEvent actionEvent) {
MainController.showView(LoginFXML.class);
} }
  • 创建main方法,启动项目
import com.dome.view.ExportClassEntityFXML;
import com.dome.view.LoginFXML;
import de.felixroske.jfxsupport.AbstractJavaFxApplicationSupport;
import javafx.stage.Stage;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; /**
* maven构建JavaFX+SpringBoot项目启动类
*/
@ComponentScan({"com.dome.view","com.dome.controller","com.dome.service"})
@SpringBootApplication
public class MainController extends AbstractJavaFxApplicationSupport { public static void main(String[] args) {
launch(MainController.class, ExportClassEntityFXML.class, args);
} @Override
public void start(Stage stage) throws Exception {
super.start(stage);
stage.setTitle("用户登录");
//窗口最大化显示
// Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
// stage.setX(primaryScreenBounds.getMinX());
// stage.setY(primaryScreenBounds.getMinY());
// stage.setWidth(primaryScreenBounds.getWidth());
// stage.setHeight(primaryScreenBounds.getHeight());
// stage.setMaximized(true);//设置窗口最大化
// stage.setFullScreen(true);//全屏显示,Esc退出
// stage.setAlwaysOnTop(true);//始终显示在其他窗口之上
}
}

其中ComponentScan用来设置扫描包的中的类。

最后项目结构入下:

(四)创建基于maven的javaFX+springboot项目,用户界面与后台逻辑分离方式的更多相关文章

  1. (三)创建基于maven的javaFX+springboot项目创建

    创建基于maven的javaFx+springboot项目有两种方式,第一种为通过非编码的方式来设计UI集成springboot:第二种为分离用户界面(UI)和后端逻辑集成springboot,其中用 ...

  2. (二)创建基于maven的javaFX项目

    首先使用IDEA创建一个javaFX项目 点击finish,这就创建完成了JavaFX项目,只有将其转换为maven项目即可,如图:

  3. 使用IDEA创建基于Maven SpringMvc项目

    使用IDEA创建基于Maven SpringMvc项目 1.通过程序启动——create project,或者file--New-projec打开New project 2.自定义groupid等信息 ...

  4. 转:基于Maven管理的JavaWeb项目目录结构参考

    通常在创建JavaWeb项目时多多少少都会遵循一些既定的比较通用的目录结构,下面分享一张基于Maven管理的JavaWeb项目目录结构参考图: 上图仅是参考,不同项目不同团队都有自己的约定和规范. 个 ...

  5. IntelliJ IDEA基于maven构建的web项目找不到jar包

    基于maven构建的springMVC项目,下载好jar包import后,运行提示ClassNotFoundException: java.lang.ClassNotFoundException: o ...

  6. 创建基于maven的项目模版

    我们在实际工作中 ,有些项目的架构是相似的,例如基于 restful的接口项目,如果每次都重新搭建一套架构或者通过拷贝建立一个项目难免有些得不偿失,这里我们可以用maven的archtype建立项目模 ...

  7. 从头开始基于Maven搭建SpringMVC+Mybatis项目(3)

    接上文内容,本节介绍基于Mybatis的查询和分页功能,并展示一个自定义的分页标签,可重复使用以简化JSP页面的开发. 从头阅读传送门 在上一节中,我们已经使用Maven搭建好了项目的基础结构,包括一 ...

  8. Springboot 创建的maven获取resource资源下的文件的两种方式

    Springboot 创建的maven项目 打包后获取resource下的资源文件的两种方式: 资源目录: resources/config/wordFileXml/wordFileRecord.xm ...

  9. 学习笔记——Maven实战(四)基于Maven的持续集成实践

    Martin的<持续集成> 相信很多读者和我一样,最早接触到持续集成的概念是来自Martin的著名文章<持续集成>,该文最早发布于2000年9月,之后在2006年进行了一次修订 ...

随机推荐

  1. rsync+inotify 实时双向同步

    前言 在遇到需要 nginx 负载均衡,承受较高并发的情况,同时会有双机相同目录内容须保持一致的需求 rsync+inotify 是一个不错的解决方案,相较于 rsync+sersync 在处理大量文 ...

  2. 性能测试 | 服务器CPU使用率高分析实例

    前面我们讨论系统调用的时候结论是耗时200ns-15us不等.不过我今天说的我的这个遭遇可能会让你进一步认识系统调用的真正开销.在本节里你会看到一个耗时2.5ms的connect系统调用,注意是毫秒, ...

  3. Android ListView多布局

    使用listview多布局会出现一点问题: 由于多个item布局给单一的item布局是不一样的,使用起来,contentview的复用会出现问题. 避免出现问题的有这几个方法: 1.重写 getVie ...

  4. Python - selectors 模块

    selectors 模块 它的功能与 linux 的 epoll,还是 select 模块,  poll 等类似: 实现高效的 I/O multiplexing ,  常用于非阻塞的 socket  ...

  5. python之scrapy模拟登陆人人网

    1.settings.py主要配置信息,包括USER_AGENT等 # -*- coding: utf-8 -*- # Scrapy settings for renren project # # F ...

  6. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_4-2.微服务下登录检验解决方案 JWT讲解

    笔记 2.微服务下登录检验解决方案 JWT讲解     简介:微服务下登录检验解决方案 JWT讲解 json wen token 1.JWT 是一个开放标准,它定义了一种用于简洁,自包含的用于通信双方 ...

  7. Docker监控:最佳实践以及cAdvisor和Prometheus监控工具的对比

    在DockerCon EU 2015上,Brian Christner阐述了“Docker监控”的概况,分享了这方面的最佳实践和Docker stats API的指南,并对比了三个流行的监控方案:cA ...

  8. 白盒测试 && 接口测试 && 自动化测试

    一.什么是白盒测试 白盒测试是一种测试策略,这种策略允许我们检查程序的内部结构,对程序的逻辑结构进行检查,从中获取测试数据.白盒测试的对象基本是源程序,所以它又称为结构测试或逻辑驱动测试,白盒测试方法 ...

  9. Swift3.0封装 AFN 的 GET&POST网络请求

    // // PSNetWorkManage.swift // WeiBoSwift // // Created by 思 彭 on 16/9/25. // Copyright © 2016年 思 彭. ...

  10. lumen添加中间件实现cookie自动加密解密

    在项目根路径下执行命令:安装illuminate/cookie包 1.composer require illuminate/cookie 2.找到同版本的laravel下的\vendor\larav ...