目录
一、功能介绍
1.ER图
2.学生管理员登陆页面
3.图书馆首页
其他几个按扭点击均会出现不同类型的书
4.学生图书馆搜索界面
5.学生注册
6.管理员后台
增加书籍
查看借阅记录
修改图书
二、功能分解
1.界面展示
在HelloApplication类里,首先定义一个公共舞台
public static Stage primaryStage;
然后创建不同的场景,定义一个开始方法展示程序运行时展示的第一个页面
public void start(Stage primaryStage) throws IOException {
this.primaryStage = primaryStage;
starScene();
}
然后创建其他场景(这里举个例子):
//学生登录
public static void starScene() {
try {
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);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
2.点击按钮切换页面
这个功能实现运用到了控制类 ,JavaFX项目在刚开始创建时有两个类,一个是HelloApplication另一个是HelloController中HelloApplication用于写各种方法并绑定不同的FXML文件,HelloController控制类处理用于控制FXML文件中的UI元素和处理逻辑。
在HelloController类中创建按钮点击时调用的HelloApplication的不同场景来实现页面转换,展示代码如下:
普通按钮点击
@FXML
public void back5(MouseEvent mouseEvent){HelloApplication.BackScene();}
这是普通按钮点击,比如关闭按钮,完成按钮;复杂一点的按钮点击事件需要获取页面数值并传入实现对应功能的包含sql语句的方法中比如:
复杂按钮点击
//管理员的登录按钮
@FXML
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语句方法执行的结果
if(ok){
HelloApplication.BackScene();//调用成功之后出现的场景
}else {
if (!errorDisplayed) {
HelloApplication.exit();//失败后调用的页面
errorDisplayed = true;
}
}
}
失败之后应出现小弹窗类型的窗口去提醒客户输入信息有误,所以这时候不能去用HelloApplication的公共舞台,需要自己搭建一个舞台。但是此时会出现一个问题就是当信息有误的情况下,一直点击按钮这个方法不断被调用会出现很多个弹窗窗口导致程序变卡也不美观,解决办法就是在HelloController类里创建一个布尔类型的成员变量为false,如果用户输入消息是错误的情况下曾加一个if判断,用于判断成员变量的值是否不为false,如果为true则调用窗口,同时设置它的值为true(注意if语句里面是!成员变量),然后再次点击时就不会多次调用弹窗方法。
3.登录注册
登陆注册功能实现需要连接数据库
创建登陆注册的页面(图为登录)
设置两个输入框的id
带有sql语句的方法
// login 学生登陆
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()是判断下一个结果是否为空,为空代表查询完毕
return true;
}
return false;
}
写登录页面登录按钮的点击方法
//学生页面的登录按钮
@FXML
public void Booklist(MouseEvent mouseEvent) throws SQLException {
u = username.getText();
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);
if(ok){
HelloApplication.BookScene();
}else {
if (!errorDisplayed) {
HelloApplication.fail();
errorDisplayed = true;
}
}
}
在FXML文件里设置控件点击事件
此时一个登录方法就完成了。注册方法跟登陆方法差不多但是要注意在注册时需要对数据库现有数据进行判断以防止重复数据出现。
注册功能的sql语句方法
//学生注册
public static boolean slogin(String name, String npassword) throws SQLException {
String sql1 = "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(1,name);
pg.setString(2,npassword);
gp.setString(1, name);
gp.setString(2, npassword);
ResultSet re = pg.executeQuery();
int up = gp.executeUpdate();//插入结果后更新的条数,如果插入成功即up不为0
while (up == 0 || re.next()){//若插入失败或者查询的结果有重复的都会返回false
return false;
}
return true;
}
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() {
return name.get();
}
public SimpleStringProperty nameProperty() {
return name;
}
public void setName(String name) {
this.name.set(name);
}
表格控件的Controller类
先定义表格控以及各列的id,查询数据库的数据后返回一个结果集(结果集类型自己定义)传输到各列上面,还有一个默认方法initialize即每次进入当前页面就会刷新表格
public class TypeController {
public static String n;
public TableView tableView;
public TableColumn name;
public TableColumn writer;
public TableColumn bank;
public static int a;
public static String k;
private boolean errorDisplayed = false;
public void initialize() throws SQLException {
allBook();
}
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);
sBookList.add(sBook);
// 设置其他属性
}
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();
// 调用删除方法,传入作者名字
delete(writerName);
}
// 从表格视图中移除选中的行
ObservableList selectedRows = selectionModel.getSelectedItems();
GtableView.getItems().removeAll(selectedRows);
} else {
// 没有选中项的情况下输出提示
System.out.println("请选择一本书");
}
}
修改
修改方法主要使用在管理员从图书馆后台选择书籍去对书籍的名字、作者、种类、库存进行修改。这里在选择某一行时要获取这一行图书的信息并存为成员变量,再点击修改时修改页面就会出现原有的信息。
//管理员看到图书页面的修改按钮
@FXML
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();
}
}else{
System.out.println("请选择一本书");
}
}
6.模糊查询
首先使用两个成员变量储存用户输入的值,这两个变量将作为sql语句条件去查询。这里是让用户可以输入书名或者作者名或者两者综合去查询。若两个都输入这时就要筛选同时符合这两个条件的书籍,这里用了MySQL的if函数
public void sou(MouseEvent mouseEvent) throws SQLException {
b = bookname.getText();
w = bookwriter.getText();
loadData();
}
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(1,b);
ps.setString(2,"%"+b+"%");
ps.setString(3,w);
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 {
loadData();
}
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);
gBookList.add(gBook);
// 设置其他属性
}
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;
starScene();
}
//登陆不成功显示的画面
public static void fail(){
try {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("win.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
stage.setTitle("登陆失败");
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//注册显示用户已存在
public static void exit(){
try {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("exit.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
stage.setTitle("注册失败");
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//还书失败
public static void backFalse(){
try {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("backfalse.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
stage.setTitle("还书失败");
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//还书成功
public static void backWin(){
try {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("backwin.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
stage.setTitle("还书成功");
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//借书成功
public static void last(){
try {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("Last.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
stage.setTitle("借书成功");
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//提醒用户还书
public static void back(){
try {
FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("back.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 500,150 );
Stage stage = new Stage();
stage.setResizable(false);
stage.setTitle("借书失败");
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//学生登录
public static void starScene() {
try {
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);
primaryStage.show();
} catch (IOException e) {
e.printStackTrace();
}
}
//管理员登陆
public static void loginScene(){
try {
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);
primaryStage.show();
}catch (IOException e){
e.printStackTrace();
}
}
//管理员看到的后台数据
public static void BackScene(){
try {
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);
primaryStage.show();
}catch (IOException e){
e.printStackTrace();
}
}
//增加书籍
public static void addBook(){
try {
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);
primaryStage.show();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//添加成功的方法
public static void Addwin(){
try {
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);
primaryStage.show();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//查看图书被借阅次数的页面
public static void inBook(){
try {
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);
primaryStage.show();
}catch (IOException e){
e.printStackTrace();
}
}
//注册的方法
public static void registerScene(){
try {
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);
primaryStage.show();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//学生登陆进去后显示的图书种类
public static void BookScene(){
try {
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);
primaryStage.show();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//管理员修改图书的页面
public static void AlterScene(){
try {
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);
primaryStage.show();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
//搜索页面
public static void select(){
try {
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);
primaryStage.show();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
launch(args);
}
}
控制器类
HelloController类
package com.example.controller;
import com.example.dao.GBook;
import com.example.dao.JDBC;
import com.example.dao.Student;
import javafx.fxml.FXML;
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 {
public int b;
public static String u;
@FXML
private TextField username;
@FXML
private PasswordField password;
@FXML
private TextField usernames;
@FXML
private PasswordField passwords;
@FXML
private TextField Name;
@FXML
private PasswordField npassword;
@FXML
private PasswordField apassword;
private boolean errorDisplayed = false;
public HelloController() {
}
//学生登陆页面的按钮点击跳转管理员登陆界面
@FXML
public void ButtonClick(MouseEvent mouseEvent){HelloApplication.loginScene();}
//管理员的登录按钮
@FXML
public void Glogin(MouseEvent mouseEvent) throws SQLException{
String y = usernames.getText();
String m = passwords.getText();
Boolean ok = Student.glogin(y,m);
if(ok){
HelloApplication.BackScene();
}else {
if (!errorDisplayed) {
HelloApplication.exit();
errorDisplayed = true;
}
}
}
//从管理员登录界面退回到学生登陆界面
@FXML
public void back1(MouseEvent mouseEvent){
HelloApplication.starScene();
}
//添加成功后继续添加书籍的按钮
@FXML
public void back4(MouseEvent mouseEvent){
HelloApplication.addBook();
}
//添加图书成功之后返回后台的按钮
@FXML
public void back5(MouseEvent mouseEvent){HelloApplication.BackScene();}
//学生页面的注册按钮
@FXML
public void register(MouseEvent mouseEvent){HelloApplication.registerScene();}
//学生页面的登录按钮
@FXML
public void Booklist(MouseEvent mouseEvent) throws SQLException {
u = username.getText();
String p = password.getText();
SelectController selectController = new SelectController();
selectController.setValues(u);
TypeController typeController = new TypeController();
typeController.setValues(u);
Boolean ok = Student.login(u,p);
if(ok){
HelloApplication.BookScene();
}else {
// Only display the error page if it hasn't been displayed before.
if (!errorDisplayed) {
HelloApplication.fail();
// Set the flag to true to indicate that the error page has been displayed.
errorDisplayed = true;
}
}
}
//学生页面的注册按钮
@FXML
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);
if (ok)
HelloApplication.starScene();
} else {
// Only display the error page if it hasn't been displayed before.
if (!errorDisplayed) {
HelloApplication.fail();
// Set the flag to true to indicate that the error page has been displayed.
errorDisplayed = true;
}
}
}
//书籍界面通过给b赋值确定图书种类
@FXML
public void type1(MouseEvent mouseEvent){
b=0;
}
@FXML
public void type2(MouseEvent mouseEvent){
b=1;
}
@FXML
public void type3(MouseEvent mouseEvent){
b=2;
}
@FXML
public void type4(MouseEvent mouseEvent){
b=3;
}
//种类界面的搜索按钮
public void select(MouseEvent mouseEvent) {
HelloApplication.select();
}
public void back7(MouseEvent mouseEvent) throws SQLException {
boolean ok = backBook();
if(ok){
HelloApplication.backWin();
}
else{
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);
ps.setString(1,u);
pd.setString(1,u);
pg.setString(1,u);
int rs=ps.executeUpdate();
int rd = pd.executeUpdate();
int rg=pg.executeUpdate();
if(rs!=0 & rd!=0){
if(rg!=0){
return true;
}else{
return false;
}
}
else {
return false;
}
}
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.fxml.FXML;
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 static String n;
public TableView tableView;
public TableColumn name;
public TableColumn writer;
public TableColumn bank;
public static int a;
public static String k;
private boolean errorDisplayed = false;
public void initialize() throws SQLException {
allBook();
}
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);
sBookList.add(sBook);
// 设置其他属性
}
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);
ps.setInt(1,a);
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);
}
@FXML
public void type1(MouseEvent mouseEvent) throws SQLException {
a=0;
loadData();
}
@FXML
public void type2(MouseEvent mouseEvent) throws SQLException {
a=1;
loadData();
}
@FXML
public void type3(MouseEvent mouseEvent) throws SQLException {
a=2;
loadData();
}
@FXML
public void type4(MouseEvent mouseEvent) throws SQLException {
a=3;
loadData();
}
//显示全部书籍
public void comein(MouseEvent mouseEvent) throws Exception {
initialize();
}
//搜索
public void select(MouseEvent mouseEvent) {
HelloApplication.select();
}
//还书
public void back7(MouseEvent mouseEvent) throws SQLException {
boolean ok = backBook();
if(ok){
HelloApplication.backWin();
allBook();
}
else {
// Only display the error page if it hasn't been displayed before.
if (!errorDisplayed) {
HelloApplication.backFalse();
// Set the flag to true to indicate that the error page has been displayed.
errorDisplayed = true;
}
}
}
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);
ps.setString(1,n);
pd.setString(1,n);
pg.setString(1,n);
int rs=ps.executeUpdate();
int rd = pd.executeUpdate();
int rg=pg.executeUpdate();
if(rs!=0 & rd!=0){
if(rg!=0){
return true;
}else{
return false;
}
}
else {
return false;
}
}
//选好书之后
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();
}
}
else{
System.out.println("请选择一本书");
}
String sql3 = "select BookName from library.user where name=?";
Connection conn = JDBC.getConn();
PreparedStatement pb = conn.prepareStatement(sql3);
pb.setString(1, n);
ResultSet rs = pb.executeQuery();
String bk =null;
while(rs.next()){
bk=rs.getString("BookName");
}
if (bk ==null) {
boolean ok = addName();
boolean kc = bank();
if(ok & kc){
HelloApplication.last();
allBook();
}else{
HelloApplication.back();
}
}
}
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);
ps.setString(1,n);
ps.setString(2,k);
pg.setString(1,k);
pg.setString(2,n);
gp.setString(1,k);
gp.setString(2,n);
int rs = ps.executeUpdate();
int rg = pg.executeUpdate();
int rp = gp.executeUpdate();
if(rs != 0 & rg !=0 & rp != 0){
return true;
}
return false;
}
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);
ps.setString(1,k);
int t = ps.executeUpdate();
if (t != 0){
return true;
}
return false;
}
//返回登陆页面
public void back9(MouseEvent mouseEvent) {
HelloApplication.starScene();
}
public void setValues(String u) {
n=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.fxml.FXML;
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 {
@FXML
private TableView tableView;
@FXML
private TableColumn name;
@FXML
private TableColumn writer;
@FXML
private TableColumn bank;
@FXML
private TextField bookname;
@FXML
private TextField bookwriter;
public String b;
public String w;
public static String n;
public static String k;
public void back7(MouseEvent mouseEvent) {
HelloApplication.BookScene();
}
public void sou(MouseEvent mouseEvent) throws SQLException {
b = bookname.getText();
w = bookwriter.getText();
loadData();
}
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(1,b);
ps.setString(2,"%"+b+"%");
ps.setString(3,w);
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();
}
}else {
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);
ps.setString(1, n);
pb.setString(1, k);
pg.setString(1,k);
pg.setString(2,n);
ResultSet re = ps.executeQuery();
ResultSet rs = pb.executeQuery();
int rg=pg.executeUpdate();
String bn = null;
int bk = 0;
while (rs.next()&re.next()&rg!=0) {
bk = rs.getInt("bank");
bn=re.getString("BookName");
}
if (bk != 0 &bn ==null) {
boolean ok = addName();
boolean kc = bank();
if(ok & kc){
HelloApplication.last();
}
} else {
HelloApplication.back();
}
}
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);
ps.setString(1,n);
ps.setString(2,k);
pg.setString(1,k);
pg.setString(2,n);
int rs = ps.executeUpdate();
int rg = pg.executeUpdate();
if(rs != 0 & rg !=0){
return true;
}
return false;
}
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);
ps.setString(1,k);
int t = ps.executeUpdate();
if (t != 0){
return true;
}
return false;
}
public void setValues(String u) {
n=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.fxml.FXML;
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;
private static String n;
public static String w;
public static String t;
public static String b;
public void initialize() throws SQLException {
loadData();
}
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);
gBookList.add(gBook);
// 设置其他属性
}
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);
ps.setString(1,writer);
int r = ps.executeUpdate();
if(r != 0){
return true;
}
return false;
}
@FXML
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();
delete(s);
}
ObservableList selectedRows = selectionModel.getSelectedItems();
GtableView.getItems().removeAll(selectedRows);
}else{
System.out.println("请选择一本书");
}
}
//添加图书
@FXML
public void AddBook(MouseEvent mouseEvent) throws SQLException {
HelloApplication.addBook();
}
//管理员看到图书页面的修改按钮
@FXML
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();
}
}else{
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();
}
} else {
System.out.println("No item is selected.");
}
}
}
增加图书页面控制类
package com.example.controller;
import com.example.dao.GBook;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseEvent;
import java.sql.SQLException;
public class AddbookController {
@FXML
private TextField Aname;
@FXML
private TextField Awriter;
@FXML
private TextField Atype;
@FXML
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);
if(ok){
HelloApplication.Addwin();
}
}
@FXML
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 Xname;
public TextField Xwriter;
public TextField Xtype;
public TextField Xbank;
public static String u;
public static String r;
public static String y;
public static int i;
public static String s;
public static String m;
public void initialize() throws SQLException {
setValue(u,r,y,s,i);
Xname.setText(u);
Xwriter.setText(r);
Xtype.setText(y);
Xbank.setText(s);
}
public void setValue(String a,String b,String c,String e,int d){
u=a;
r=b;
y=c;
s=e;
i=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);
pg.setString(1,XType);
ResultSet re = pg.executeQuery();
while (re.next()){
m= re.getString("book_type");
}
ps.setString(1,XName);
ps.setString(2,XWriter);
ps.setString(3,m);
ps.setString(4,Xbank);
ps.setInt(5,i);
int rs = ps.executeUpdate();
if(rs ==0){
return false;
}
return true;
}
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);
if(ok) {
HelloApplication.BackScene();
}
else{
HelloApplication.last();
}
}
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.fxml.FXML;
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 {
public static String r;
@FXML
private TableView BtableView;
@FXML
private TableColumn Bookname;
@FXML
private TableColumn Bname;
public void setValue(String s){
r=s;
}
public void initialize() throws SQLException {
loadData();
}
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);
ps.setString(1,r);
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);
BookList.add(Book);
// 设置其他属性
}
Bookname.setCellValueFactory(new PropertyValueFactory<>("name"));
Bname.setCellValueFactory(new PropertyValueFactory<>("username"));
BtableView.setItems(BookList);
}
public void back11(MouseEvent mouseEvent) {
HelloApplication.BackScene();
}
}
实体类
图书馆
package com.example.dao;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class SBook {
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() {
return name.get();
}
public SimpleStringProperty nameProperty() {
return name;
}
public void setName(String name) {
this.name.set(name);
}
public String getWriter(){
return writer.get();
}
public SimpleStringProperty writerProperty() {
return writer;
}
public void setWriter(String writer) {
this.writer.set(writer);
}
public SimpleIntegerProperty bankProperty() {
return bank;
}
public void setBank(int bank) {
this.bank.set(bank);
}
public int getBank(){
return bank.get();
}
}
管理员后台类
package com.example.dao;
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;
public class GBook {
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() {
return name.get();
}
public SimpleStringProperty nameProperty() {
return name;
}
public void setName(String name) {
this.name.set(name);
}
public String getWriter(){
return writer.get();
}
public SimpleStringProperty writerProperty() {
return writer;
}
public void setWriter(String writer) {
this.writer.set(writer);
}
public SimpleStringProperty bankProperty() {
return bank;
}
public void setBank(String bank) {
this.bank.set(bank);
}
public String getBank(){
return bank.get();
}
public String getUsername(){
return username.get();
}
public SimpleStringProperty usernameProperty() {
return username;
}
public void setUsername(String username) {
this.username.set(username);
}
public SimpleStringProperty typeProperty() {
return type;
}
public SimpleIntegerProperty idProperty() {
return id;
}
public void setId(int id) {
this.id.set(id);
}
public int getId(){
return id.get();
}
public void setType(String type) {
this.type.set(type);
}
public String getType(){
return type.get();
}
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);
pg.setString(1,Aname);
pg.setString(2,Awriter);
gp.setString(1,Aname);
gp.setString(2,Awriter);
gp.setString(3,Atype);
ResultSet re=pg.executeQuery();
int up=gp.executeUpdate();
if(up ==0 && re.next()){
System.out.println("增加失败");
return false;
}
return true;
}
}
type对应type-name类
package com.example.dao;
import javafx.beans.property.SimpleStringProperty;
public class BookName{
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() {
return name.get();
}
public SimpleStringProperty nameProperty() {
return name;
}
public void setName(String name) {
this.name.set(name);
}
public String getUsername(){
return username.get();
}
public SimpleStringProperty usernameProperty() {
return username;
}
public void setUsername(String username) {
this.username.set(username);
}
}
JDBC封装以及一个带有sql语句的方法的类
SQL语句方法类
package com.example.dao;
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 class Student {
// login 学生登陆
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();
while (res.next()) {
return true;
}
return false;
}
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();
while (res.next()) {
return true;
}
return false;
}
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(1,name);
pg.setString(2,npassword);
gp.setString(1, name);
gp.setString(2, npassword);
ResultSet re = pg.executeQuery();
int up = gp.executeUpdate();
while (up ==0 || re.next()){
return false;
}
return true;
}
}
JDBC封装类
package com.example.dao;
import java.sql.*;
import java.util.Objects;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBC {
/**
* URL地址
*/
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 = "*******";//换为自己的数据库密码
/**
* 返回数据库连接对象
*
* @return
*/
public static Connection getConn() {
try {
return DriverManager.getConnection(URL, USER, PASSWORD);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
/**
* 关闭资源
*
* @param rs
* @param stat
* @param conn
*/
public static void close(ResultSet rs, Statement stat, Connection conn) {
try {
if (rs != null) {
rs.close();
}
if (stat != null) {
stat.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 封装通用的更新操作(即通过该方法实现对弈任意数据表的insert,update,delete操作)
*
* @param sql 需要执行的SQL语句
* @param params 执行SQL语句时需要传递进去参数
* @return 执行结果
*/
public static boolean exeUpdate(String sql, Object... params) {
//获取连接对象
Connection conn = getConn();
PreparedStatement ps = null;
try {
//获取预编译对象
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) {
e.printStackTrace();
} finally {
//关闭资源
close(null, ps, conn);
}
return false;
}
}
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">
<children>
<ImageView fitHeight="468.0" fitWidth="723.0" layoutY="2.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<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">
<font>
<Font size="23.0" />
</font>
</Label>
<Label layoutX="130.0" layoutY="189.0" prefHeight="27.0" prefWidth="115.0" text="Student ID:">
<font>
<Font size="20.0" />
</font></Label>
<Label layoutX="100.0" layoutY="242.0" />
<Label layoutX="134.0" layoutY="280.0" prefHeight="27.0" prefWidth="108.0" text="Password:">
<font>
<Font size="20.0" />
</font></Label>
<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" />
</children>
</AnchorPane>
登陆失败
<?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">
<children>
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<Label layoutX="99.0" layoutY="42.0" prefHeight="44.0" prefWidth="467.0" text="请输入正确信息">
<font>
<Font size="34.0" />
</font></Label>
</children>
</AnchorPane>
注册
<?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">
<children>
<ImageView fitHeight="475.0" fitWidth="737.0" layoutY="-4.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image></ImageView>
<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="姓名:">
<font>
<Font size="20.0" />
</font></Label>
<Label layoutX="178.0" layoutY="232.0" text="密码:">
<font>
<Font size="20.0" />
</font></Label>
<Label layoutX="152.0" layoutY="293.0" text="确认密码:">
<font>
<Font size="20.0" />
</font>
</Label>
<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" />
</children>
</AnchorPane>
注册失败
<?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">
<children>
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<Label layoutX="99.0" layoutY="42.0" prefHeight="44.0" prefWidth="467.0" text="用户已存在">
<font>
<Font size="34.0" />
</font></Label>
</children>
</AnchorPane>
管理员登陆
<?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">
<children>
<ImageView fitHeight="476.0" fitWidth="721.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image></ImageView>
<Label contentDisplay="CENTER" layoutX="196.0" layoutY="167.0" prefHeight="30.0" prefWidth="69.0" text="账号:">
<font>
<Font size="23.0" />
</font>
</Label>
<Label layoutX="196.0" layoutY="246.0" text="密码:">
<font>
<Font size="23.0" />
</font>
</Label>
<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="管理员你好">
<font>
<Font size="24.0" />
</font>
</Label>
<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" />
</children>
</Pane>
图书馆
<?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">
<children>
<ImageView fitHeight="499.0" fitWidth="749.0" layoutX="-13.0" layoutY="-35.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image></ImageView>
<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">
<columns>
<TableColumn fx:id="name" prefWidth="203.99996948242188" text="书籍名" />
<TableColumn fx:id="writer" prefWidth="187.3333740234375" text="作者" />
<TableColumn fx:id="bank" prefWidth="78.0" text="库存" />
</columns>
</TableView>
<Button layoutX="367.0" layoutY="412.0" mnemonicParsing="false" onMouseClicked="#OK" prefHeight="37.0" prefWidth="66.0" text="选好了" />
</children>
</AnchorPane>
搜索
<?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">
<children>
<ImageView fitHeight="669.0" fitWidth="993.0" layoutX="-206.0" layoutY="-7.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image></ImageView>
<TableView fx:id="tableView" layoutX="137.0" layoutY="105.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="371.0" prefWidth="409.0">
<columns>
<TableColumn fx:id="name" prefWidth="145.3333282470703" text="书籍名" />
<TableColumn fx:id="writer" prefWidth="126.0" text="作者" />
<TableColumn fx:id="bank" prefWidth="136.0" text="库存" />
</columns>
</TableView>
<Label layoutX="266.0" layoutY="14.0" prefHeight="33.0" prefWidth="184.0" text="欢迎来到网上图书馆">
<font>
<Font size="20.0" />
</font>
</Label>
<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="书名:">
<font>
<Font size="18.0" />
</font></Label>
<Label layoutX="331.0" layoutY="61.0" text="作者:">
<font>
<Font size="18.0" />
</font></Label>
<Button layoutX="524.0" layoutY="62.0" mnemonicParsing="false" onMouseClicked="#sou" prefHeight="23.0" prefWidth="28.0" text="搜" />
</children>
</Pane>
借书成功
<?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">
<children>
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<Label layoutX="99.0" layoutY="42.0" prefHeight="44.0" prefWidth="467.0" text="借书成功">
<font>
<Font size="34.0" />
</font></Label>
</children>
</AnchorPane>
借书失败
<?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">
<children>
<ImageView fitHeight="433.0" fitWidth="744.0" layoutX="-170.0" layoutY="-101.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<Label layoutX="24.0" layoutY="14.0" prefHeight="44.0" prefWidth="467.0" text="1.请先还书">
<font>
<Font size="34.0" />
</font></Label>
<Label layoutX="24.0" layoutY="71.0" prefHeight="44.0" prefWidth="393.0" text="2.没有库存请耐心等待">
<font>
<Font size="34.0" />
</font>
</Label>
</children>
</AnchorPane>
还书成功
<?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">
<children>
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<Label layoutX="99.0" layoutY="42.0" prefHeight="44.0" prefWidth="467.0" text="还书成功">
<font>
<Font size="34.0" />
</font></Label>
</children>
</AnchorPane>
还书失败
<?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">
<children>
<ImageView fitHeight="540.0" fitWidth="744.0" layoutX="-230.0" layoutY="-141.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<Label layoutX="99.0" layoutY="42.0" prefHeight="44.0" prefWidth="467.0" text="还书失败,请先借书">
<font>
<Font size="34.0" />
</font></Label>
</children>
</AnchorPane>
管理员后台
<?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">
<children>
<ImageView fitHeight="690.0" fitWidth="967.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<TableView fx:id="GtableView" layoutX="146.0" layoutY="118.0" prefHeight="410.0" prefWidth="398.0">
<columns>
<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="种类" />
</columns>
</TableView>
<Button layoutX="484.0" layoutY="70.0" mnemonicParsing="false" onMouseClicked="#AddBook" text="增加书籍" />
<Label layoutX="287.0" layoutY="40.0" text="欢迎管理员">
<font>
<Font size="23.0" />
</font>
</Label>
<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="查看" />
</children>
</AnchorPane>
查询借阅记录
<?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">
<children>
<ImageView fitHeight="444.0" fitWidth="679.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image></ImageView>
<TableView fx:id="BtableView" layoutX="140.0" layoutY="103.0" prefHeight="297.0" prefWidth="423.0">
<columns>
<TableColumn fx:id="Bookname" prefWidth="200.6666488647461" text="书名" />
<TableColumn fx:id="Bname" prefWidth="222.00003051757812" text="借阅人" />
</columns>
</TableView>
<Button layoutX="546.0" layoutY="48.0" mnemonicParsing="false" onMouseClicked="#back11" prefHeight="23.0" prefWidth="36.0" text="X" />
</children>
</AnchorPane>
修改图书
<?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">
<children>
<ImageView fitHeight="477.0" fitWidth="704.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<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="书名:">
<font>
<Font size="21.0" />
</font></Label>
<Label layoutX="219.0" layoutY="175.0" text="作者名:">
<font>
<Font size="21.0" />
</font></Label>
<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="种类:">
<font>
<Font size="21.0" />
</font>
</Label>
<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="库存:">
<font>
<Font size="21.0" />
</font></Label>
<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="修改图书">
<font>
<Font size="29.0" />
</font>
</Label>
</children>
</AnchorPane>
增加图书
<?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">
<children>
<ImageView fitHeight="501.0" fitWidth="739.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image>
</ImageView>
<Label layoutX="296.0" layoutY="93.0" text="添加书籍">
<font>
<Font size="23.0" />
</font>
</Label>
<Label layoutX="178.0" layoutY="170.0" text="书名:">
<font>
<Font size="22.0" />
</font>
</Label>
<Label layoutX="188.0" layoutY="246.0" text="作者:">
<font>
<Font size="22.0" />
</font>
</Label>
<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="种类:">
<font>
<Font size="22.0" />
</font>
</Label>
<TextField fx:id="Atype" layoutX="362.0" layoutY="313.0" prefHeight="30.0" prefWidth="161.0" />
</children>
</AnchorPane>
增加成功
<?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">
<children>
<ImageView fitHeight="417.0" fitWidth="714.0" layoutY="-5.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="file:/C:/Users/Lenovo/Desktop/sea.jpg" />
</image></ImageView>
<Label layoutX="237.0" layoutY="104.0" text="添加成功">
<font>
<Font size="38.0" />
</font>
</Label>
<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="返回" />
</children>
</AnchorPane>
OK写完了,里面还有很多小瑕疵,修改图书时不能把图书修改的跟数据库现存的一样,以及修改图书还是要填写数字。欢迎大家来评论区探讨!!