目录
一、功能介绍
1.ER图
2.学生管理员登陆页面
3.图书馆首页
4.学生图书馆搜索界面
5.学生注册
6.管理员后台
增加书籍
查看借阅记录
编辑
修改图书
二、功能分解
1.界面展示
2.点击按钮切换页面
普通按钮点击
复杂按钮点击
3.登录注册
创建登陆注册的页面(图为登录)
设置两个输入框的id
带有sql语句的方法
写登录页面登录按钮的点击方法
在FXML文件里设置控件点击事件
注册功能的sql语句方法
4.表格控件的绑定
实体类
表格控件的Controller类
FXML文件
给整个表格设置id
给各列设置id
5.增、删、改
从表格选择图书并删除
修改
6.模糊查询
7.左外连接查询
三、总代码
页面类
控制器类
HelloController类
图书馆控制类
搜索页面控制类
管理员后台控制类
增加图书页面控制类
修改图书控制类
管理员查看图书借阅记录控制类
实体类
图书馆
管理员后台类
type对应type-name类
JDBC封装以及一个带有sql语句的方法的类
SQL语句方法类
JDBC封装类
FXML文件
登录
登陆失败
注册
注册失败
管理员登陆
图书馆
搜索
借书成功
借书失败
还书成功
还书失败
管理员后台
查询借阅记录
修改图书
增加图书
增加成功
1.ER图
2.学生
管理员登陆页面
3.图书馆首页
其他几个按扭点击均会出现不同类型的书
4.学生图书馆
搜索界面
5.学生
注册
6.
管理员后台
增加书籍
查看借阅记录
修改图书
1.界面展示
在HelloApplication类里,首先定义一个公共舞台
public static Stage primaryStage;
然后创建不同的场景,定义一个开始方法展示程序运行时展示的第一个页面
public void start(Stage primaryStage) throws IOException {
this.primaryStage = primaryStage;
然后创建其他场景(这里举个例子):
public static void starScene() {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693,460);
primaryStage.setResizable(
false);
//设置页面大小固定
primaryStage.setTitle(
"欢迎来到网络图书馆");
primaryStage.setScene(scene);
} catch (IOException e) {
2.点击按钮切换页面
这个功能实现运用到了控制类 ,JavaFX项目在刚开始创建时有两个类,一个是HelloApplication另一个是HelloController中HelloApplication用于写各种方法并绑定不同的FXML文件,HelloController控制类处理用于控制FXML文件中的UI元素和处理逻辑。
在HelloController类中创建按钮点击时调用的HelloApplication的不同场景来实现页面转换,展示代码如下:
普通按钮点击
public void back5(MouseEvent mouseEvent){HelloApplication.BackScene();}
这是普通按钮点击,比如关闭按钮,完成按钮;复杂一点的按钮点击事件需要获取页面数值并传入实现对应功能的包含sql语句的方法中比如:
复杂按钮点击
public void Glogin(MouseEvent mouseEvent) throws SQLException{
String y = usernames.getText();//获取id为usernames的textfield的数值
String m = passwords.getText();
Boolean ok = Student.glogin(y,m);//使用boolean类型的变量去判断sql语句方法执行的结果
HelloApplication.BackScene();//调用成功之后出现的场景
HelloApplication.exit();//失败后调用的页面
失败之后应出现小弹窗类型的窗口去提醒客户输入信息有误,所以这时候不能去用HelloApplication的公共舞台,需要自己搭建一个舞台。但是此时会出现一个问题就是当信息有误的情况下,一直点击按钮这个方法不断被调用会出现很多个弹窗窗口导致程序变卡也不美观,解决办法就是在HelloController类里创建一个布尔类型的成员变量为false,如果用户输入消息是错误的情况下曾加一个if判断,用于判断成员变量的值是否不为false,如果为true则调用窗口,同时设置它的值为true(注意if语句里面是!成员变量),然后再次点击时就不会多次调用弹窗方法。
3.
登录注册
登陆注册功能实现需要连接数据库
创建登陆
注册的页面(图为
登录)
设置两个输入框的id
带有sql语句的方法
public static boolean login(String username ,String password) throws SQLException {
String sql = "select id from library.user where name = ? and password = ? and type=0";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, username);
ps.setString(2, password);
ResultSet res
= ps.executeQuery();
//保存
查询结果的集合
while (res.
next()) {
//res.
next()是判断下一个结果是否为空,为空代表
查询完毕
写
登录页面
登录按钮的点击方法
public void Booklist(MouseEvent mouseEvent) throws SQLException {
String p = password.getText();
//SelectController selectController = new SelectController();
//selectController.setValues(u);//将变量u通过这种方法传到SelectController类里
//TypeController typeController = new TypeController();
//typeController.setValues(u);这一部分跟
登录方法没有
关系
Boolean ok = Student.login(u,p);
HelloApplication.BookScene();
在FXML
文件里
设置控件点击
事件
此时一个登录方法就完成了。注册方法跟登陆方法差不多但是要注意在注册时需要对数据库现有数据进行判断以防止重复数据出现。
注册功能的sql语句方法
public static boolean slogin(String name, String npassword) throws SQLException {
String sql
1 = "select id from library.user where name = ? and password = ? and type=0";
//学生和
管理员在
数据库的一张表通过
type的值来区别。这句sql语句是
查询库里是否存在有着一模一样的
用户名和
密码的
数据
String sql = "insert into library.user (name,password,type) values(?,?,0)";
Connection conn = JDBC.getConn();
PreparedStatement pg =conn.prepareStatement(sql1);
PreparedStatement gp = conn.prepareStatement(sql);
pg.setString(2,npassword);
gp.setString(2, npassword);
ResultSet re = pg.executeQuery();
int
up = gp.executeUpdate();
//插入结果后
更新的条数,如果插入成功即
up不为
0
while (
up == 0 || re.
next()){
//若插入失败或者
查询的结果有重复的都会返回
false
4.表格控件的绑定
实体类
实体类里主要包括各种实例变量的定义以及get、set方法和构造函数对实例变量进行初始化,注意实例变量的类型必须是SimpleStringProperty类
private final SimpleStringProperty name;
private final SimpleStringProperty writer;
private final SimpleIntegerProperty bank;
public SBook(String name, String writer, int bank) {
this.name = new SimpleStringProperty(name);
this.writer= new SimpleStringProperty(writer);
this.bank= new SimpleIntegerProperty(bank);
public String getName() {
public SimpleStringProperty nameProperty() {
public void setName(String name) {
表格控件的Controller类
先定义表格控以及各列的id,查询数据库的数据后返回一个结果集(结果集类型自己定义)传输到各列上面,还有一个默认方法initialize即每次进入当前页面就会刷新表格
public class TypeController {
public TableView tableView;
public TableColumn writer;
private boolean errorDisplayed = false;
public void initialize() throws SQLException {
public void allBook()throws SQLException{
String sql = "select name,writer,bank from library.book_list";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
ObservableList<SBook> sBookList = FXCollections.observableArrayList();
while (resultSet.next()) {
String sBookName=resultSet.getString("name");
String sBookWriter=resultSet.getString("writer");
int sBookBank = resultSet.getInt("bank");
SBook sBook = new SBook(sBookName,sBookWriter,sBookBank);
name.setCellValueFactory(new PropertyValueFactory<>("name"));
writer.setCellValueFactory(new PropertyValueFactory<>("writer"));
bank.setCellValueFactory(new PropertyValueFactory<>("bank"));
tableView.setItems(sBookList);
FXML
文件
给整个表格
设置id
给各列
设置id
5.增、删、改
这几个功能分别用在注册功能、借书还书功能、管理员修改功能、管理员删除功能。
从表格选择图书并
删除
借书跟删除功能除了sql语句不一样大体一样,这里删除为例:
public void delete(MouseEvent mouseEvent) throws SQLException {
TableView.TableViewSelectionModel<GBook> selectionModel = GtableView.getSelectionModel();
ObservableList<GBook> selectedItems = selectionModel.getSelectedItems();
if (!selectedItems.isEmpty()) {
GBook selectedItem = selectedItems.get(0);
if (selectedItem != null) {
String writerName = selectedItem.getWriter();
ObservableList selectedRows = selectionModel.getSelectedItems();
GtableView.getItems().removeAll(selectedRows);
System.out.println("请选择一本书");
修改
修改方法主要使用在管理员从图书馆后台选择书籍去对书籍的名字、作者、种类、库存进行修改。这里在选择某一行时要获取这一行图书的信息并存为成员变量,再点击修改时修改页面就会出现原有的信息。
public void alter(MouseEvent mouseEvent){
TableView.TableViewSelectionModel<GBook> selectionModel = GtableView.getSelectionModel();
ObservableList<GBook> selectedItems = selectionModel.getSelectedItems();
if(!selectedItems.isEmpty()){
GBook selectedItem = selectedItems.get(0);
if (selectedItem != null) {
int i = selectedItem.getId();
n = selectedItem.getName();
w = selectedItem.getWriter();
t = selectedItem.getType();
b = selectedItem.getBank();
AlterController alterController=new AlterController();
alterController.setValue(n,w,t,b,i);
//传入
修改的页面Controller类,使TextFiled获取
数据
HelloApplication.AlterScene();
System.out.println("请选择一本书");
6.模糊
查询
首先使用两个成员变量储存用户输入的值,这两个变量将作为sql语句条件去查询。这里是让用户可以输入书名或者作者名或者两者综合去查询。若两个都输入这时就要筛选同时符合这两个条件的书籍,这里用了MySQL的if函数
public void sou(MouseEvent mouseEvent) throws SQLException {
w = bookwriter.getText();
public void loadData() throws SQLException {
String sql = "select name,writer,bank from library.book_list where if(? = ,true, name like ?) and if( ? = ,true,writer like ?)";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(2,"%"+b+"%");
ps.setString(4,"%"+w+"%");
ResultSet resultSet = ps.executeQuery();
ObservableList<SBook> sBookList = FXCollections.observableArrayList();
while (resultSet.next()) {
String sBookName=resultSet.getString("name");
String sBookWriter=resultSet.getString("writer");
int sBookBank = resultSet.getInt("bank");
SBook sBook = new SBook(sBookName,sBookWriter,sBookBank);
sBookList.
add(sBook);
// 设置其他属性
name.setCellValueFactory(new PropertyValueFactory<>("name"));
writer.setCellValueFactory(new PropertyValueFactory<>("writer"));
bank.setCellValueFactory(new PropertyValueFactory<>("bank"));
tableView.setItems(sBookList);
7.左外连接
查询
这是两表一起查询,在数据库里图书种类我用了数字代替,而在管理员后台看到的是每种数字代表的图书种类。我又额外增添一个type跟type-name对应的表。
public void initialize() throws SQLException {
public void loadData() throws SQLException {
String sql
= "select * from book_list as b left join book_type as bt on b.type=bt.book_type";
//查询图书数字代表的名称采用左外连接的方法
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
ObservableList<GBook> gBookList = FXCollections.observableArrayList();
while (resultSet.next()) {
String gBookName=resultSet.getString("name");
String gBookWriter=resultSet.getString("writer");
String gBookBank = resultSet.getString("bank");
int gBookId= resultSet.getInt("id");
String gBookUserName=resultSet.getString("username");
String gBookType= resultSet.getString("type_name");
GBook gBook = new GBook(gBookName,gBookWriter,gBookBank,gBookUserName,gBookType,gBookId);
Gname.setCellValueFactory(new PropertyValueFactory<>("name"));
Gwriter.setCellValueFactory(new PropertyValueFactory<>("writer"));
Gbank.setCellValueFactory(new PropertyValueFactory<>("bank"));
UserName.setCellValueFactory(new PropertyValueFactory<>("username"));
Gtype.setCellValueFactory(new PropertyValueFactory<>("type"));
GtableView.setItems(gBookList);
虽然采用MVC对包进行分类但是代码并没有遵守。每个表格控件对应一个Controller类,其他功能基本在HelloController类里,带有sql的方法有的写在控制类里,有的单独写了一个类。
页面类
package com.example.controller;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
public static Stage primaryStage;
public void start(Stage primaryStage) throws IOException {
this.primaryStage = primaryStage;
public static void fail(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("win.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
} catch (IOException e) {
public static void exit(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("exit.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
} catch (IOException e) {
public static void backFalse(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("backfalse.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
} catch (IOException e) {
public static void backWin(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("backwin.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
} catch (IOException e) {
public static void last(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("Last.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
} catch (IOException e) {
public static void back(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("back.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
} catch (IOException e) {
public static void starScene() {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693,460);
primaryStage.setResizable(false);
primaryStage.setTitle(
"欢迎来到网络图书馆");
primaryStage.setScene(scene);
} catch (IOException e) {
public static void loginScene(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("login.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693, 460);
primaryStage.setResizable(false);
primaryStage.setTitle(
"图书馆管理");
primaryStage.setScene(scene);
public static void BackScene(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("backstage.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693, 580);
primaryStage.setResizable(false);
primaryStage.setTitle(
"后台管理");
primaryStage.setScene(scene);
public static void addBook(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("addBook.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693, 500);
primaryStage.setResizable(false);
primaryStage.setTitle(
"后台管理");
primaryStage.setScene(scene);
} catch (IOException e) {
throw new RuntimeException(e);
public static void Addwin(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("addwin.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693, 500);
primaryStage.setResizable(false);
primaryStage.setTitle("成功了");
primaryStage.setScene(scene);
} catch (IOException e) {
throw new RuntimeException(e);
public static void inBook(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("inBook.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693, 400);
primaryStage.setResizable(false);
primaryStage.setTitle(
"后台管理");
primaryStage.setScene(scene);
public static void registerScene(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("zhuce.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693, 460);
primaryStage.setResizable(false);
primaryStage.setTitle(
"注册");
primaryStage.setScene(scene);
} catch (IOException e) {
throw new RuntimeException(e);
public static void BookScene(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("Booktype.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693, 460);
primaryStage.setResizable(false);
primaryStage.setTitle("图书种类");
primaryStage.setScene(scene);
} catch (IOException e) {
throw new RuntimeException(e);
public static void AlterScene(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("alter.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693, 400);
primaryStage.setResizable(false);
primaryStage.setTitle(
"修改");
primaryStage.setScene(scene);
} catch (IOException e) {
throw new RuntimeException(e);
public static void select(){
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("select.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 693, 515);
primaryStage.setResizable(false);
primaryStage.setTitle(
"搜索");
primaryStage.setScene(scene);
} catch (IOException e) {
throw new RuntimeException(e);
public static void main(String[] args) {
控制器类
HelloController类
package com.example.controller;
import com.example.dao.GBook;
import com.example.dao.JDBC;
import com.example.dao.Student;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Objects;
public class HelloController {
private TextField username;
private PasswordField password;
private TextField usernames;
private PasswordField passwords;
private PasswordField npassword;
private PasswordField apassword;
private boolean errorDisplayed = false;
public HelloController() {
public void ButtonClick(MouseEvent mouseEvent){HelloApplication.loginScene();}
public void Glogin(MouseEvent mouseEvent) throws SQLException{
String y = usernames.getText();
String m = passwords.getText();
Boolean ok = Student.glogin(y,m);
HelloApplication.BackScene();
public void back1(MouseEvent mouseEvent){
HelloApplication.starScene();
public void back4(MouseEvent mouseEvent){
HelloApplication.addBook();
public void back5(MouseEvent mouseEvent){HelloApplication.BackScene();}
public void register(MouseEvent mouseEvent){HelloApplication.registerScene();}
public void Booklist(MouseEvent mouseEvent) throws SQLException {
String p = password.getText();
SelectController selectController = new SelectController();
selectController.setValues(u);
TypeController typeController = new TypeController();
typeController.setValues(u);
Boolean ok = Student.login(u,p);
HelloApplication.BookScene();
// Only display the error page if it hasnt been displayed before.
// Set the flag to true to indicate that the error page has been displayed.
public void regis(MouseEvent mouseEvent) throws SQLException {
String u = Name.getText();
String p = npassword.getText();
String a = apassword.getText();
if (Objects.equals(p, a)) {
Boolean ok = Student.slogin(u, p);
HelloApplication.starScene();
// Only display the error page if it hasnt been displayed before.
// Set the flag to true to indicate that the error page has been displayed.
public void type1(MouseEvent mouseEvent){
public void type2(MouseEvent mouseEvent){
public void type3(MouseEvent mouseEvent){
public void type4(MouseEvent mouseEvent){
public void select(MouseEvent mouseEvent) {
HelloApplication.select();
public void back7(MouseEvent mouseEvent) throws SQLException {
HelloApplication.backWin();
HelloApplication.backFalse();
public boolean backBook() throws SQLException {
String sql = "update library.user set BookName = null where name = ?";
String sql2 = "update library.book_list set bank = bank+1 where UserName = ? ";
String sql3 = "update library.book_list set UserName = null where UserName = ?";
Connection con = JDBC.getConn();
PreparedStatement ps = con.prepareStatement(sql);
PreparedStatement pd = con.prepareStatement(sql2);
PreparedStatement pg = con.prepareStatement(sql3);
int rs=ps.executeUpdate();
int rd = pd.executeUpdate();
int rg=pg.executeUpdate();
public void back9(MouseEvent mouseEvent) {
HelloApplication.starScene();
public void back10(MouseEvent mouseEvent) {
HelloApplication.starScene();
图书馆
控制类
package com.example.controller;
import com.example.dao.JDBC;
import com.example.dao.SBook;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class TypeController {
public TableView tableView;
public TableColumn writer;
private boolean errorDisplayed = false;
public void initialize() throws SQLException {
public void allBook()throws SQLException{
String sql = "select name,writer,bank from library.book_list";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
ObservableList<SBook> sBookList = FXCollections.observableArrayList();
while (resultSet.next()) {
String sBookName=resultSet.getString("name");
String sBookWriter=resultSet.getString("writer");
int sBookBank = resultSet.getInt("bank");
SBook sBook = new SBook(sBookName,sBookWriter,sBookBank);
name.setCellValueFactory(new PropertyValueFactory<>("name"));
writer.setCellValueFactory(new PropertyValueFactory<>("writer"));
bank.setCellValueFactory(new PropertyValueFactory<>("bank"));
tableView.setItems(sBookList);
public void loadData() throws SQLException {
String sql = "select name,writer,bank from library.book_list where type = ?";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
ObservableList<SBook> sBookList = FXCollections.observableArrayList();
while (resultSet.next()) {
String sBookName=resultSet.getString("name");
String sBookWriter=resultSet.getString("writer");
int sBookBank = resultSet.getInt("bank");
SBook sBook = new SBook(sBookName,sBookWriter,sBookBank);
name.setCellValueFactory(new PropertyValueFactory<>("name"));
writer.setCellValueFactory(new PropertyValueFactory<>("writer"));
bank.setCellValueFactory(new PropertyValueFactory<>("bank"));
tableView.setItems(sBookList);
public void type1(MouseEvent mouseEvent) throws SQLException {
public void type2(MouseEvent mouseEvent) throws SQLException {
public void type3(MouseEvent mouseEvent) throws SQLException {
public void type4(MouseEvent mouseEvent) throws SQLException {
public void comein(MouseEvent mouseEvent) throws Exception {
public void select(MouseEvent mouseEvent) {
HelloApplication.select();
public void back7(MouseEvent mouseEvent) throws SQLException {
HelloApplication.backWin();
// Only display the error page if it hasnt been displayed before.
HelloApplication.backFalse();
// Set the flag to true to indicate that the error page has been displayed.
public boolean backBook() throws SQLException {
String sql = "update library.user set BookName = null where name = ?";
String sql2 = "update library.book_list set bank = bank+1 where UserName = ? ";
String sql3 = "update library.book_list set UserName = null where UserName = ?";
Connection con = JDBC.getConn();
PreparedStatement ps = con.prepareStatement(sql);
PreparedStatement pd = con.prepareStatement(sql2);
PreparedStatement pg = con.prepareStatement(sql3);
int rs=ps.executeUpdate();
int rd = pd.executeUpdate();
int rg=pg.executeUpdate();
public void OK(MouseEvent mouseEvent) throws SQLException {
TableView.TableViewSelectionModel<SBook> selectionModel = tableView.getSelectionModel();
ObservableList<SBook> selectedItems = selectionModel.getSelectedItems();
if(!selectedItems.isEmpty()){
SBook selectedItem = selectedItems.get(0);
if(selectedItem != null){
k = selectedItem.getName();
System.out.println("请选择一本书");
String sql3 = "select BookName from library.user where name=?";
Connection conn = JDBC.getConn();
PreparedStatement pb = conn.prepareStatement(sql3);
ResultSet rs = pb.executeQuery();
bk=rs.getString("BookName");
public boolean addName() throws SQLException {
String sql = "update library.book_list set UserName = ? where name = ?";
String sql2 = "update library.user set BookName = ? where name = ?";
String sql3="insert into library.book_name (BookName,name) values(?,?)";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
PreparedStatement pg = conn.prepareStatement(sql2);
PreparedStatement gp = conn.prepareStatement(sql3);
int rs = ps.executeUpdate();
int rg = pg.executeUpdate();
int rp = gp.executeUpdate();
if(rs != 0 & rg !=0 & rp != 0){
public boolean bank() throws SQLException{
String sql ="update library.book_list set bank = bank-1 where name = ?";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
int t = ps.executeUpdate();
public void back9(MouseEvent mouseEvent) {
HelloApplication.starScene();
public void setValues(String u) {
搜索页面
控制类
package com.example.controller;
import com.example.dao.JDBC;
import com.example.dao.SBook;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class SelectController {
private TableView tableView;
private TableColumn name;
private TableColumn writer;
private TableColumn bank;
private TextField bookname;
private TextField bookwriter;
public void back7(MouseEvent mouseEvent) {
HelloApplication.BookScene();
public void sou(MouseEvent mouseEvent) throws SQLException {
w = bookwriter.getText();
public void loadData() throws SQLException {
String sql = "select name,writer,bank from library.book_list where if(? = ,true, name like ?) and if( ? = ,true,writer like ?)";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(2,"%"+b+"%");
ps.setString(4,"%"+w+"%");
ResultSet resultSet = ps.executeQuery();
ObservableList<SBook> sBookList = FXCollections.observableArrayList();
while (resultSet.next()) {
String sBookName=resultSet.getString("name");
String sBookWriter=resultSet.getString("writer");
int sBookBank = resultSet.getInt("bank");
SBook sBook = new SBook(sBookName,sBookWriter,sBookBank);
sBookList.
add(sBook);
// 设置其他属性
name.setCellValueFactory(new PropertyValueFactory<>("name"));
writer.setCellValueFactory(new PropertyValueFactory<>("writer"));
bank.setCellValueFactory(new PropertyValueFactory<>("bank"));
tableView.setItems(sBookList);
public void last(MouseEvent mouseEvent)throws SQLException {
TableView.TableViewSelectionModel<SBook> selectionModel = tableView.getSelectionModel();
ObservableList<SBook> selectedItems = selectionModel.getSelectedItems();
if(!selectedItems.isEmpty()){
SBook selectedItem = selectedItems.get(0);
if(selectedItem != null){
k = selectedItem.getName();
System.out.println("请选择一本书");
String sql = "select BookName from library.user where name = ?";
String sql3 = "select bank from library.book_list where name=?";
String sql2 ="insert into library.book_name (BookName,name) values(?,?)";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
PreparedStatement pb = conn.prepareStatement(sql3);
PreparedStatement pg = conn.prepareStatement(sql2);
ResultSet re = ps.executeQuery();
ResultSet rs = pb.executeQuery();
int rg=pg.executeUpdate();
while (rs.next()&re.next()&rg!=0) {
bn=re.getString("BookName");
if (bk != 0 &bn ==null) {
public boolean addName() throws SQLException {
String sql = "update library.book_list set UserName = ? where name = ?";
String sql2 = "update library.user set BookName = ? where name = ?";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
PreparedStatement pg = conn.prepareStatement(sql2);
int rs = ps.executeUpdate();
int rg = pg.executeUpdate();
public boolean bank() throws SQLException{
String sql ="update library.book_list set bank = bank-1 where name = ?";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
int t = ps.executeUpdate();
public void setValues(String u) {
管理员后台
控制类
package com.example.controller;
import com.example.dao.GBook;
import com.example.dao.JDBC;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class GbookController {
public TableView GtableView;
public TableColumn Gname;
public TableColumn Gwriter;
public TableColumn Gbank;
public TableColumn Gtype;
public TableColumn UserName;
public void initialize() throws SQLException {
public void loadData() throws SQLException {
String sql = "select * from book_list as b left join book_type as bt on b.type=bt.book_type";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
ObservableList<GBook> gBookList = FXCollections.observableArrayList();
while (resultSet.next()) {
String gBookName=resultSet.getString("name");
String gBookWriter=resultSet.getString("writer");
String gBookBank = resultSet.getString("bank");
int gBookId= resultSet.getInt("id");
String gBookUserName=resultSet.getString("username");
String gBookType= resultSet.getString("type_name");
GBook gBook = new GBook(gBookName,gBookWriter,gBookBank,gBookUserName,gBookType,gBookId);
Gname.setCellValueFactory(new PropertyValueFactory<>("name"));
Gwriter.setCellValueFactory(new PropertyValueFactory<>("writer"));
Gbank.setCellValueFactory(new PropertyValueFactory<>("bank"));
UserName.setCellValueFactory(new PropertyValueFactory<>("username"));
Gtype.setCellValueFactory(new PropertyValueFactory<>("type"));
GtableView.setItems(gBookList);
public Boolean delete(String writer)throws SQLException {
String sql="delete from library.book_list where writer = ? ";
Connection con = JDBC.getConn();
PreparedStatement ps = con.prepareStatement(sql);
int r = ps.executeUpdate();
public void back2(MouseEvent mouseEvent){
HelloApplication.loginScene();
public void delete(MouseEvent mouseEvent) throws SQLException {
TableView.TableViewSelectionModel<GBook> selectionModel = GtableView.getSelectionModel();
ObservableList<GBook> selectedItems = selectionModel.getSelectedItems();
if(!selectedItems.isEmpty()){
GBook selectedItem = selectedItems.get(0); // 假设只选择了一行
if (selectedItem != null) {
String s = selectedItem.getWriter();
ObservableList selectedRows = selectionModel.getSelectedItems();
GtableView.getItems().removeAll(selectedRows);
System.out.println("请选择一本书");
public void AddBook(MouseEvent mouseEvent) throws SQLException {
HelloApplication.addBook();
public void alter(MouseEvent mouseEvent){
TableView.TableViewSelectionModel<GBook> selectionModel = GtableView.getSelectionModel();
ObservableList<GBook> selectedItems = selectionModel.getSelectedItems();
if(!selectedItems.isEmpty()){
GBook selectedItem = selectedItems.get(0);
if (selectedItem != null) {
int i = selectedItem.getId();
n = selectedItem.getName();
w = selectedItem.getWriter();
t = selectedItem.getType();
b = selectedItem.getBank();
AlterController alterController=new AlterController();
alterController.setValue(n,w,t,b,i);
HelloApplication.AlterScene();
System.out.println("请选择一本书");
public void look(MouseEvent mouseEvent) {
TableView.TableViewSelectionModel<GBook> selectionModel = GtableView.getSelectionModel();
ObservableList<GBook> selectedItems = selectionModel.getSelectedItems();
if (!selectedItems.isEmpty()) {
GBook selectedItem = selectedItems.get(0);
if (selectedItem != null) {
String s = selectedItem.getName();
InbookController inbookController = new InbookController();
inbookController.setValue(s);
HelloApplication.inBook();
System.out.println("No item is selected.");
增加图书页面
控制类
package com.example.controller;
import com.example.dao.GBook;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import java.sql.SQLException;
public class AddbookController {
private TextField Awriter;
public void addwin(MouseEvent mouseEvent) throws SQLException {
String n = Aname.getText();
String w = Awriter.getText();
String t = Atype.getText();
Boolean ok = GBook.addBook(n,w,t);
HelloApplication.Addwin();
public void back3(MouseEvent mouseEvent){
HelloApplication.BackScene();
修改图书
控制类
package com.example.controller;
import com.example.dao.JDBC;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class AlterController {
public TextField Xwriter;
public void initialize() throws SQLException {
public void setValue(String a,String b,String c,String e,int d){
public boolean alter(String XName,String XWriter,String XType,String Xbank) throws SQLException {
String sql1="select book_type from library.book_type where type_name = ?";
String sql = "update library.book_list set name=?,writer=? ,type=?,bank=? where id= ? ";
Connection con= JDBC.getConn();
PreparedStatement pg=con.prepareStatement(sql1);
PreparedStatement ps = con.prepareStatement(sql);
ResultSet re = pg.executeQuery();
m= re.getString("book_type");
int rs = ps.executeUpdate();
public void finish(MouseEvent mouseEvent) throws SQLException {
String m = Xname.getText();
String r = Xwriter.getText();
String p = Xtype.getText();
String q = Xbank.getText();
boolean ok = alter(m,r,p,q);
HelloApplication.BackScene();
public void back8(MouseEvent mouseEvent) {
HelloApplication.BackScene();
管理员
查看图书借阅记录
控制类
package com.example.controller;
import com.example.dao.BookName;
import com.example.dao.JDBC;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class InbookController {
private TableView BtableView;
private TableColumn Bookname;
private TableColumn Bname;
public void setValue(String s){
public void initialize() throws SQLException {
public void loadData() throws SQLException {
String sql = "select BookName,name from library.book_name where BookName = ?";
Connection conn = JDBC.getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
ObservableList<BookName> BookList = FXCollections.observableArrayList();
while (resultSet.next()) {
String gBookName=resultSet.getString("BookName");
String gBookUserName=resultSet.getString("name");
BookName Book = new BookName(gBookName,gBookUserName);
Bookname.setCellValueFactory(new PropertyValueFactory<>("name"));
Bname.setCellValueFactory(new PropertyValueFactory<>("username"));
BtableView.setItems(BookList);
public void back11(MouseEvent mouseEvent) {
HelloApplication.BackScene();
实体类
图书馆
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
private final SimpleStringProperty name;
private final SimpleStringProperty writer;
private final SimpleIntegerProperty bank;
public SBook(String name, String writer, int bank) {
this.name = new SimpleStringProperty(name);
this.writer= new SimpleStringProperty(writer);
this.bank= new SimpleIntegerProperty(bank);
public String getName() {
public SimpleStringProperty nameProperty() {
public void setName(String name) {
public String getWriter(){
public SimpleStringProperty writerProperty() {
public void setWriter(String writer) {
public SimpleIntegerProperty bankProperty() {
public void setBank(int bank) {
管理员后台类
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
private final SimpleStringProperty name;
private final SimpleStringProperty writer;
private final SimpleStringProperty username;
private final SimpleStringProperty bank;
private final SimpleStringProperty type;
private final SimpleIntegerProperty id;
public GBook(String name, String writer, String bank,String username ,String type,int id) {
this.name = new SimpleStringProperty(name);
this.writer= new SimpleStringProperty(writer);
this.bank= new SimpleStringProperty(bank);
this.id= new SimpleIntegerProperty(id);
this.username= new SimpleStringProperty(username);
this.type= new SimpleStringProperty(type);
public String getName() {
public SimpleStringProperty nameProperty() {
public void setName(String name) {
public String getWriter(){
public SimpleStringProperty writerProperty() {
public void setWriter(String writer) {
public SimpleStringProperty bankProperty() {
public void setBank(String bank) {
public String getUsername(){
public SimpleStringProperty usernameProperty() {
public void setUsername(String username) {
this.username.set(username);
public SimpleStringProperty typeProperty() {
public SimpleIntegerProperty idProperty() {
public void setId(int id) {
public void setType(String type) {
public static boolean addBook(String Aname,String Awriter,String Atype) throws SQLException {
String sql1="select name,writer from library.book_list where name =? and writer = ?";
String sql = "insert into library.book_list (name,writer,bank,type) values(?,?,1,?)";
Connection conn = JDBC.getConn();
PreparedStatement pg = conn.prepareStatement(sql1);
PreparedStatement gp = conn.prepareStatement(sql);
ResultSet re=pg.executeQuery();
int up=gp.executeUpdate();
System.out.println("增加失败");
type对应type-name类
import javafx.beans.property.SimpleStringProperty;
private final SimpleStringProperty name;
private final SimpleStringProperty username;
public BookName(String name, String username) {
this.name = new SimpleStringProperty(name);
this.username = new SimpleStringProperty(username);
public String getName() {
public SimpleStringProperty nameProperty() {
public void setName(String name) {
public String getUsername(){
public SimpleStringProperty usernameProperty() {
public void setUsername(String username) {
this.username.set(username);
JDBC封装以及一个带有sql语句的方法的类
SQL语句方法类
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.example.dao.JDBC;
import static com.example.dao.JDBC.getConn;
public static boolean login(String username ,String password) throws SQLException {
String sql = "select id from library.user where name = ? and password = ? and type=0";
Connection conn = getConn();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, username);
ps.setString(2, password);
ResultSet res = ps.executeQuery();
public static boolean glogin(String usernames, String passwords) throws SQLException {
String sql = "select id from library.user where name = ? and password = ? and type=1";
Connection conn = getConn();
PreparedStatement gp = conn.prepareStatement(sql);
gp.setString(1, usernames);
gp.setString(2, passwords);
ResultSet res = gp.executeQuery();
public static boolean slogin(String name, String npassword) throws SQLException {
String sql1 = "select id from library.user where name = ? and password = ? and type=0";
String sql = "insert into library.user (name,password,type) values(?,?,0)";
Connection conn = getConn();
PreparedStatement pg =conn.prepareStatement(sql1);
PreparedStatement gp = conn.prepareStatement(sql);
pg.setString(2,npassword);
gp.setString(2, npassword);
ResultSet re = pg.executeQuery();
int up = gp.executeUpdate();
while (up ==0 || re.next()){
JDBC封装类
import java.util.Objects;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
private static final String URL = "jdbc:mysql://127.0.0.1:3306/library?useSSL=false";
private static final String USER = "root";
private static
final String PASSWORD
= "*******";
//换为自己的
数据库密码
public static Connection getConn() {
return DriverManager.getConnection(URL, USER, PASSWORD);
} catch (SQLException e) {
public static void close(ResultSet rs, Statement stat, Connection conn) {
} catch (SQLException e) {
* 封装通用的
更新操作(即通过该方法实现对弈任意
数据表的insert,update,
delete操作)
* @param params 执行SQL语句时需要传递进去参数
public static boolean exeUpdate(String sql, Object... params) {
Connection conn = getConn();
PreparedStatement ps = null;
ps = conn.prepareStatement(sql);
if (Objects.nonNull(params)) {
for (int i = 0; i < params.length; i++) {
ps.setObject(i + 1, params[i]);
return ps.executeUpdate() > 0;
} catch (SQLException e) {
FXML
文件
登录
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="468.0" prefWidth="705.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.HelloController">
<ImageView fitHeight="468.0" fitWidth="723.0" layoutY="2.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Button fx:id="login" layoutX="156.0" layoutY="361.0" mnemonicParsing="false" onMouseClicked="#Booklist" prefHeight="27.0" prefWidth="90.0" text="login" textFill="#691818" />
<Label contentDisplay="CENTER" layoutX="246.0" layoutY="74.0" prefHeight="52.0" prefWidth="115.0" text="Welcome">
<Label layoutX="130.0" layoutY="189.0" prefHeight="27.0" prefWidth="115.0" text="Student ID:">
<Label layoutX="100.0" layoutY="242.0" />
<Label layoutX="134.0" layoutY="280.0" prefHeight="27.0" prefWidth="108.0" text="Password:">
<PasswordField fx:id
="password" layoutX
="345.0" layoutY
="280.0" prefHeight
="27.0" prefWidth
="161.0" promptText
="请输入密码" />
<Button layoutX
="573.0" layoutY
="74.0" mnemonicParsing
="false" onMouseClicked
="#ButtonClick" prefHeight
="35.0" prefWidth
="34.0" style
="-fx-background-color: powderblue;" text
="管" textFill
="#691818" textOverrun
="CLIP" />
<TextField fx:id
="username" layoutX
="345.0" layoutY
="189.0" prefHeight
="27.0" prefWidth
="161.0" promptText
="请输入账号" />
<Button layoutX="426.0" layoutY="361.0" mnemonicParsing="false" onMouseClicked="#register" prefHeight="27.0" prefWidth="90.0" text="sign in" />
登陆失败
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="115.0" prefWidth="463.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1">
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Label layoutX="99.0" layoutY="42.0" prefHeight="44.0" prefWidth="467.0" text="请输入正确信息">
注册
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="468.0" prefWidth="705.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.HelloController">
<ImageView fitHeight="475.0" fitWidth="737.0" layoutY="-4.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Button layoutX
="321.0" layoutY
="382.0" mnemonicParsing
="false" onMouseClicked
="#regis" prefHeight
="27.0" prefWidth
="70.0" text
="注册" />
<Label layoutX="179.0" layoutY="156.0" text="姓名:">
<Label layoutX
="178.0" layoutY
="232.0" text
="密码:">
<Label layoutX
="152.0" layoutY
="293.0" text
="确认密码:">
<PasswordField fx:id="npassword" layoutX="350.0" layoutY="234.0" />
<PasswordField fx:id="apassword" layoutX="350.0" layoutY="295.0" />
<TextField fx:id="Name" layoutX="350.0" layoutY="170.0" />
<Button layoutX="523.0" layoutY="106.0" mnemonicParsing="false" onMouseClicked="#back10" prefHeight="23.0" prefWidth="30.0" text="X" />
注册失败
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="115.0" prefWidth="463.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1">
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Label layoutX
="99.0" layoutY
="42.0" prefHeight
="44.0" prefWidth
="467.0" text
="用户已存在">
管理员登陆
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="468.0" prefWidth="705.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.HelloController">
<ImageView fitHeight="476.0" fitWidth="721.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Label contentDisplay
="CENTER" layoutX
="196.0" layoutY
="167.0" prefHeight
="30.0" prefWidth
="69.0" text
="账号:">
<Label layoutX
="196.0" layoutY
="246.0" text
="密码:">
<TextField fx:id="usernames" layoutX="353.0" layoutY="166.0" prefHeight="32.0" prefWidth="183.0" />
<PasswordField fx:id="passwords" layoutX="353.0" layoutY="245.0" prefHeight="32.0" prefWidth="183.0" />
<Label layoutX
="277.0" layoutY
="105.0" prefHeight
="32.0" prefWidth
="123.0" text
="管理员你好">
<Button fx:id="glogin" layoutX="302.0" layoutY="314.0" mnemonicParsing="false" onMouseClicked="#Glogin" prefHeight="32.0" prefWidth="73.0" text="登陆" />
<Button layoutX="583.0" layoutY="30.0" mnemonicParsing="false" onMouseClicked="#back1" prefHeight="32.0" prefWidth="31.0" style="-fx-background-color: powderblue;" text="X" textFill="#691818" />
图书馆
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="428.0" prefWidth="693.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.TypeController">
<ImageView fitHeight="499.0" fitWidth="749.0" layoutX="-13.0" layoutY="-35.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Button layoutX="26.0" layoutY="57.0" mnemonicParsing="false" onMouseClicked="#type1" prefHeight="37.0" prefWidth="66.0" text="历史小说" />
<Button layoutX="26.0" layoutY="195.0" mnemonicParsing="false" onMouseClicked="#type3" prefHeight="37.0" prefWidth="66.0" text="霸道总裁" />
<Button layoutX="26.0" layoutY="267.0" mnemonicParsing="false" onMouseClicked="#type4" prefHeight="37.0" prefWidth="66.0" text="悬疑探案" />
<Button layoutX="26.0" layoutY="124.0" mnemonicParsing="false" onMouseClicked="#type2" prefHeight="37.0" prefWidth="66.0" text="仙侠玄幻" />
<Button layoutX="24.0" layoutY="339.0" mnemonicParsing="false" onMouseClicked="#comein" prefHeight="37.0" prefWidth="66.0" text="全部" />
<Button layoutX
="507.0" layoutY
="29.0" mnemonicParsing
="false" onMouseClicked
="#select" prefHeight
="37.0" prefWidth
="66.0" text
="搜索" />
<Button layoutX="201.0" layoutY="29.0" mnemonicParsing="false" onMouseClicked="#back7" prefHeight="37.0" prefWidth="66.0" text="还书" />
<Button layoutX="587.0" layoutY="2.0" mnemonicParsing="false" onMouseClicked="#back9" prefHeight="23.0" prefWidth="35.0" text="X" />
<TableView fx:id="tableView" layoutX="165.0" layoutY="85.0" prefHeight="311.0" prefWidth="470.0">
<TableColumn fx:id="name" prefWidth="203.99996948242188" text="书籍名" />
<TableColumn fx:id="writer" prefWidth="187.3333740234375" text="作者" />
<TableColumn fx:id="bank" prefWidth="78.0" text="库存" />
<Button layoutX="367.0" layoutY="412.0" mnemonicParsing="false" onMouseClicked="#OK" prefHeight="37.0" prefWidth="66.0" text="选好了" />
搜索
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<Pane prefHeight="656.0" prefWidth="628.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.SelectController">
<ImageView fitHeight="669.0" fitWidth="993.0" layoutX="-206.0" layoutY="-7.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<TableView fx:id="tableView" layoutX="137.0" layoutY="105.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="371.0" prefWidth="409.0">
<TableColumn fx:id="name" prefWidth="145.3333282470703" text="书籍名" />
<TableColumn fx:id="writer" prefWidth="126.0" text="作者" />
<TableColumn fx:id="bank" prefWidth="136.0" text="库存" />
<Label layoutX="266.0" layoutY="14.0" prefHeight="33.0" prefWidth="184.0" text="欢迎来到网上图书馆">
<Button layoutX="504.0" layoutY="19.0" mnemonicParsing="false" onMouseClicked="#back7" text="返回" />
<Button layoutX="316.0" layoutY="491.0" mnemonicParsing="false" onMouseClicked="#last" text="选好了" />
<TextField fx:id="bookname" layoutX="191.0" layoutY="61.0" prefHeight="23.0" prefWidth="124.0" />
<TextField fx:id="bookwriter" layoutX="388.0" layoutY="62.0" prefHeight="23.0" prefWidth="124.0" />
<Label layoutX="130.0" layoutY="61.0" prefHeight="24.0" prefWidth="61.0" text="书名:">
<Label layoutX="331.0" layoutY="61.0" text="作者:">
<Button layoutX="524.0" layoutY="62.0" mnemonicParsing="false" onMouseClicked="#sou" prefHeight="23.0" prefWidth="28.0" text="搜" />
借书成功
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="115.0" prefWidth="463.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1">
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Label layoutX="99.0" layoutY="42.0" prefHeight="44.0" prefWidth="467.0" text="借书成功">
借书失败
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="115.0" prefWidth="463.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1">
<ImageView fitHeight="433.0" fitWidth="744.0" layoutX="-170.0" layoutY="-101.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Label layoutX="24.0" layoutY="14.0" prefHeight="44.0" prefWidth="467.0" text="1.请先还书">
<Label layoutX="24.0" layoutY="71.0" prefHeight="44.0" prefWidth="393.0" text="2.没有库存请耐心等待">
还书成功
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="115.0" prefWidth="463.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1">
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Label layoutX="99.0" layoutY="42.0" prefHeight="44.0" prefWidth="467.0" text="还书成功">
还书失败
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="115.0" prefWidth="463.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1">
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Label layoutX="99.0" layoutY="42.0" prefHeight="44.0" prefWidth="467.0" text="还书失败,请先借书">
管理员后台
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="552.0" prefWidth="697.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.GbookController">
<ImageView fitHeight="690.0" fitWidth="967.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<TableView fx:id="GtableView" layoutX="146.0" layoutY="118.0" prefHeight="410.0" prefWidth="398.0">
<TableColumn fx:id="Gname" prefWidth="111.0" text="书籍名" />
<TableColumn fx:id="Gwriter" prefWidth="93.66665649414062" text="作者" />
<TableColumn fx:id="UserName" prefWidth="91.00003051757812" text="借阅人" />
<TableColumn fx:id="Gbank" prefWidth="56.0" text="库存" />
<TableColumn fx:id="Gtype" prefWidth="43.6666259765625" text="种类" />
<Button layoutX="484.0" layoutY="70.0" mnemonicParsing="false" onMouseClicked="#AddBook" text="增加书籍" />
<Label layoutX
="287.0" layoutY
="40.0" text
="欢迎管理员">
<Button layoutX="510.0" layoutY="28.0" mnemonicParsing="false" onMouseClicked="#back2" prefHeight="23.0" prefWidth="26.0" style="-fx-background-color: powderblue;" text="X" textFill="#691818" />
<Button layoutX
="157.0" layoutY
="549.0" mnemonicParsing
="false" onMouseClicked
="#alter" text
="修改" />
<Button layoutX
="484.0" layoutY
="549.0" mnemonicParsing
="false" onMouseClicked
="#delete" text
="删除" />
<Button layoutX
="325.0" layoutY
="549.0" mnemonicParsing
="false" onMouseClicked
="#look" prefHeight
="16.0" prefWidth
="40.0" text
="查看" />
查询借阅记录
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="444.0" prefWidth="668.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.InbookController">
<ImageView fitHeight="444.0" fitWidth="679.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<TableView fx:id="BtableView" layoutX="140.0" layoutY="103.0" prefHeight="297.0" prefWidth="423.0">
<TableColumn fx:id="Bookname" prefWidth="200.6666488647461" text="书名" />
<TableColumn fx:id="Bname" prefWidth="222.00003051757812" text="借阅人" />
<Button layoutX="546.0" layoutY="48.0" mnemonicParsing="false" onMouseClicked="#back11" prefHeight="23.0" prefWidth="36.0" text="X" />
修改图书
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="470.0" prefWidth="699.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.AlterController">
<ImageView fitHeight="477.0" fitWidth="704.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Button layoutX="303.0" layoutY="351.0" mnemonicParsing="false" onMouseClicked="#finish" prefHeight="34.0" prefWidth="51.0" text="确定" />
<Label layoutX="240.0" layoutY="113.0" prefHeight="28.0" prefWidth="63.0" text="书名:">
<Label layoutX="219.0" layoutY="175.0" text="作者名:">
<TextField fx:id="Xname" layoutX="378.0" layoutY="113.0" prefHeight="28.0" prefWidth="161.0" promptText="请输入正确信息" />
<TextField fx:id="Xwriter" layoutX="378.0" layoutY="175.0" prefHeight="28.0" prefWidth="161.0" promptText="请输入正确信息" />
<Label layoutX="238.0" layoutY="227.0" text="种类:">
<TextField fx:id
="Xtype" layoutX
="378.0" layoutY
="227.0" prefHeight
="28.0" prefWidth
="161.0" promptText
="请输入文字" />
<Button layoutX="568.0" layoutY="51.0" mnemonicParsing="false" onMouseClicked="#back8" prefHeight="23.0" prefWidth="34.0" text="X" />
<Label layoutX="240.0" layoutY="290.0" text="库存:">
<TextField fx:id="Xbank" layoutX="378.0" layoutY="290.0" prefHeight="28.0" prefWidth="161.0" promptText="请输入数字" />
<Label layoutX
="270.0" layoutY
="44.0" text
="修改图书">
增加图书
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="473.0" prefWidth="730.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.AddbookController">
<ImageView fitHeight="501.0" fitWidth="739.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Label layoutX="296.0" layoutY="93.0" text="添加书籍">
<Label layoutX="178.0" layoutY="170.0" text="书名:">
<Label layoutX="188.0" layoutY="246.0" text="作者:">
<TextField fx:id="Aname" layoutX="362.0" layoutY="177.0" prefHeight="30.0" prefWidth="161.0" />
<TextField fx:id="Awriter" layoutX="362.0" layoutY="246.0" prefHeight="30.0" prefWidth="161.0" />
<Button layoutX="484.0" layoutY="386.0" mnemonicParsing="false" onMouseClicked="#addwin" prefHeight="29.0" prefWidth="51.0" text="OK" />
<Button layoutX="535.0" layoutY="81.0" mnemonicParsing="false" onMouseClicked="#back3" text="返回" />
<Label layoutX="188.0" layoutY="317.0" text="种类:">
<TextField fx:id="Atype" layoutX="362.0" layoutY="313.0" prefHeight="30.0" prefWidth="161.0" />
增加成功
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane prefHeight="412.0" prefWidth="619.0" xmlns="http://javafx.com/javafx/11.0.14-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.controller.HelloController">
<ImageView fitHeight="417.0" fitWidth="714.0" layoutY="-5.0" pickOnBounds="true" preserveRatio="true">
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
<Label layoutX="237.0" layoutY="104.0" text="添加成功">
<Button layoutX="169.0" layoutY="252.0" mnemonicParsing="false" onMouseClicked="#back4" prefHeight="35.0" prefWidth="67.0" text="继续添加" />
<Button layoutX="427.0" layoutY="252.0" mnemonicParsing="false" onMouseClicked="#back5" prefHeight="35.0" prefWidth="67.0" text="返回" />
OK写完了,里面还有很多小瑕疵,修改图书时不能把图书修改的跟数据库现存的一样,以及修改图书还是要填写数字。欢迎大家来评论区探讨!!