使用springboot创建表视图

时间:2018-12-02 04:55:36

标签: database postgresql spring-boot tableview

我是一名学习使用Springboot和数据库的学生,但是我的教授不是很有帮助。我正在做一些需要我有文本字段来更新/创建客户的工作。我在使用字段填充表格时遇到麻烦。我所拥有的只是一个创建的表。我知道我必须将字段保存到数据库中并上传到tableview中,但是我尝试的所有操作都不适合我。我将非常感谢您的帮助。 我知道我们的团队代码远不是很好,但是如果我能得到一般的想法,我肯定我们可以解决。 预先谢谢你!

这是我的fxml代码

?xml version="1.0" encoding="UTF-8"?>

 <?import javafx.geometry.Insets?>
 <?import javafx.scene.control.Button?>
  <?import javafx.scene.control.Label?>
 <?import javafx.scene.control.ScrollPane?>
 <?import javafx.scene.control.TableColumn?>
 <?import javafx.scene.control.TableView?>
 <?import javafx.scene.control.TextField?>
 <?import javafx.scene.control.ToggleButton?>
  <?import javafx.scene.effect.DropShadow?>
  <?import javafx.scene.image.ImageView?>
  <?import javafx.scene.layout.AnchorPane?>
  <?import javafx.scene.layout.ColumnConstraints?>
  <?import javafx.scene.layout.GridPane?>
 <?import javafx.scene.layout.HBox?>
 <?import javafx.scene.layout.Pane?>
 <?import javafx.scene.layout.RowConstraints?>
 <?import javafx.scene.layout.VBox?>
 <?import javafx.scene.text.Font?>

 <VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="600.0"    
 minWidth="1280.0" prefHeight="800.0" prefWidth="1280.0" 
  xmlns="http://javafx.com/javafx/10.0.1" 
  xmlns:fx="http://javafx.com/fxml/1" 



fx:controller="wonder.wondercakecis3368project.
controller.CustomerController">

 <HBox style="-fx-background-color: white;" VBox.vgrow="ALWAYS">
    <VBox style="-fx-background-color: #49C2FE;">
         <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" 
 minHeight="118.0" minWidth="226.0" prefHeight="118.0" prefWidth="226.0"   
style="-
 fx-background-color: transparent;">
            <ImageView fitHeight="118.0" fitWidth="226.0" layoutX="43.0" 
  layoutY="22.0" pickOnBounds="true" AnchorPane.bottomAnchor="0.0" 
  AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" 
 AnchorPane.topAnchor="0.0">
                <!--                    <image>
                                        <Image url="@../image/logo1.png" />
                                    </image>-->
            </ImageView>

        </AnchorPane>
        <ScrollPane fitToHeight="true" hbarPolicy="NEVER" style="-fx-
 background-color: #ffdcde;" styleClass="edge-to-edge" VBox.vgrow="ALWAYS">
            <content>
                <VBox minWidth="-Infinity" prefHeight="452.0"    
  prefWidth="226.0" style="-fx-background-color: #205F89;">

                    <ToggleButton fx:id="btnkanbanboard" 
  alignment="CENTER_RIGHT" contentDisplay="RIGHT" graphicTextGap="95.0" 
 minHeight="50.0" mnemonicParsing="false" onAction="#gotoKanbanBoard" 
  prefHeight="50.0" prefWidth="227.0" styleClass="navbtn">
                        <padding>
                            <Insets left="10.0" right="10.0" />
                        </padding>
                        <graphic>
                            <HBox alignment="CENTER_LEFT">
                                <children>
                                    <Label prefHeight="25.0" 
 prefWidth="90.0" style="-fx-font-size: 14px;" text="Kanban Board">
                                        <font>
                                            <Font size="11.0" />
                                        </font>
                                    </Label>
                                    <Pane HBox.hgrow="ALWAYS" />
                                    <!--                                      <ImageView fitHeight="35.0" 
  fitWidth="35.0" pickOnBounds="true" preserveRatio="true">
                                                                                <Image url="@../../image/icon/dashboard.png" />

</ImageView>-->
                                </children>
                                <padding>
                                    <Insets left="10.0" />
                                </padding>
                                <opaqueInsets>
                                    <Insets left="10.0" />
                                </opaqueInsets>
                            </HBox>
                        </graphic>
                    </ToggleButton>

                    <ToggleButton fx:id="btnorder" alignment="CENTER_RIGHT" 
 contentDisplay="RIGHT" graphicTextGap="128.0" layoutX="10.0" 
 layoutY="10.0" 
 minHeight="50.0" mnemonicParsing="false" onAction="#gotoOrder" 
  prefHeight="50.0" prefWidth="227.0" styleClass="navbtn">
                        <graphic>
                            <HBox alignment="CENTER_LEFT">
                                <children>
                                    <Label style="-fx-font-size: 14px;" 
  text="Order">
                                        <font>
                                            <Font size="11.0" />
                                        </font>
                                    </Label>
                                    <Pane HBox.hgrow="ALWAYS" />

                                </children>
                                <padding>
                                    <Insets left="10.0" />
                                </padding>
                            </HBox>
                        </graphic>
                        <padding>
                            <Insets left="10.0" right="10.0" />
                        </padding>
                    </ToggleButton>

                    <ToggleButton fx:id="btncustomer" 
  alignment="CENTER_RIGHT" contentDisplay="RIGHT" graphicTextGap="100.0" 
  layoutX="10.0" layoutY="162.0" minHeight="50.0" mnemonicParsing="false" 
  onAction="#gotoCustomer" prefHeight="50.0" prefWidth="227.0" style="-fx-
 border-
 color: green;" styleClass="navbtn">
                        <graphic>
                            <HBox alignment="CENTER_LEFT">
                                <children>
                                     <Label style="-fx-font-size: 14px;" 
 text="Customer">
                                        <font>
                                            <Font size="11.0" />
                                        </font>
                                    </Label>
                                    <Pane HBox.hgrow="ALWAYS" />

                                </children>
                                <padding>
                                    <Insets left="10.0" />
                                </padding>
                            </HBox>
                        </graphic>
                        <padding>
                            <Insets left="10.0" right="10.0" />
                        </padding>
                    </ToggleButton>

                      <ToggleButton fx:id="btnemployee" 
  alignment="CENTER_RIGHT" contentDisplay="RIGHT" graphicTextGap="100.0" 
  layoutX="10.0" layoutY="162.0" minHeight="50.0" mnemonicParsing="false" 
   onAction="#gotoEmployee" prefHeight="50.0" prefWidth="227.0"  
 styleClass="navbtn">
                        <graphic>
                            <HBox alignment="CENTER_LEFT">
                                <children>
                                    <Label style="-fx-font-size: 14px;" 
  text="Employee">
                                        <font>
                                            <Font size="11.0" />
                                        </font></Label>
                                    <Pane HBox.hgrow="ALWAYS" />

                                </children>
                                <padding>
                                    <Insets left="10.0" />
                                </padding>
                            </HBox>
                        </graphic>
                        <padding>
                            <Insets left="10.0" right="10.0" />
                        </padding>
                    </ToggleButton>

                    <ToggleButton fx:id="btnreport" 
   alignment="CENTER_RIGHT" contentDisplay="RIGHT" graphicTextGap="113.0" 
  layoutX="10.0" layoutY="200.0" minHeight="50.0" mnemonicParsing="false" 
  onAction="#gotoReport" prefHeight="50.0" prefWidth="227.0" 
  styleClass="navbtn">
                        <graphic>
                            <HBox alignment="CENTER_LEFT">
                                <children>
                                    <Label style="-fx-font-size: 14px;" 
  text="Report">
                                        <font>
                                            <Font size="11.0" />
                                        </font></Label>
                                    <Pane HBox.hgrow="ALWAYS" />

                                </children>
                                <padding>
                                    <Insets left="10.0" />
                                </padding>
                            </HBox>
                        </graphic>
                        <padding>
                            <Insets left="10.0" right="10.0" />
                        </padding>
                    </ToggleButton>

                    <effect>
                        <DropShadow height="25.45" 
   radius="14.079999999999998" spread="0.18" width="32.87" />
                    </effect>

                </VBox>
            </content>
        </ScrollPane>
    </VBox>

    <VBox maxHeight="1.7976931348623157E308" 
  maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS">
        <HBox alignment="CENTER_RIGHT" maxHeight="-Infinity" minHeight="-
  Infinity" prefHeight="45.0" spacing="15.0" style="-fx-background-color: 
#205F89;">
            <children>
                <Label alignment="CENTER_RIGHT" contentDisplay="CENTER" 
  prefHeight="45.0" prefWidth="184.0" text="Welcome, User!"    
 textFill="#FEFEFE">
                    <font>
                        <Font name="System Bold" size="12.0" />
                    </font>
           </Label>
                <Button id="logoutbtn" fx:id="btnlogout" 
 mnemonicParsing="false" onAction="#logout" prefHeight="29.0"    
 prefWidth="121.0" 
  text="Exit" />
            </children>
            <padding>
                <Insets right="20.0" />
            </padding>
        </HBox>

        <GridPane fx:id="module" prefHeight="557.0" prefWidth="1054.0" 
  VBox.vgrow="ALWAYS">
            <columnConstraints>
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
            </columnConstraints>
            <rowConstraints>
           <RowConstraints maxHeight="735.6667582194011" minHeight="10.0" 
  prefHeight="472.33331298828125" vgrow="SOMETIMES" />
            </rowConstraints>
        <children>
           <Pane prefHeight="603.0" prefWidth="1054.0">
              <children>
                 <Pane layoutY="411.0" prefHeight="339.0" 
  prefWidth="1054.0">
                    <children>
                       <Button fx:id="updatecustomer" layoutX="477.0" 
 layoutY="143.0" mnemonicParsing="false" prefHeight="53.0" prefWidth="98.0" 
 text="Update" />
                       <Button fx:id="createcustomer"  layoutX="324.0" 
  layoutY="143.0" mnemonicParsing="false" prefHeight="53.0" p   
  refWidth="98.0" 
  text="Create" />
                       <Button fx:id="deletecustomer" layoutX="631.0" 
  layoutY="143.0" mnemonicParsing="false" prefHeight="53.0" 
 prefWidth="98.0" 
 text="Delete" />
                       <TextField fx:id="input_lastname" layoutX="59.0" 
  layoutY="27.0" text="Last Name" />
                       <TextField fx:id="input_firstname" layoutX="257.0" 
   layoutY="27.0" text="First Name" />
                       <TextField fx:id="input_organization" 
   layoutX="452.0" layoutY="27.0" text="Organization" />
                       <TextField fx:id="input_phone" layoutX="655.0" 
   layoutY="27.0" text="Phone" />
                       <TextField fx:id="input_email" layoutX="852.0" 
  layoutY="27.0" text="Email" />
                       <TextField fx:id="input_address" layoutX="59.0" 
  layoutY="77.0" text="Address" />
                       <TextField fx:id="input_city" layoutX="257.0" 
  layoutY="77.0" text="City" />
                       <TextField fx:id="input_state" layoutX="452.0" 
 layoutY="77.0" text="State" />
                        <TextField fx:id="input_zipcode" layoutX="655.0" 
 layoutY="77.0" text="Zip Code" />
                       <TextField fx:id="input_country" layoutX="852.0" 
 layoutY="77.0" text="Country" />
                    </children>
                 </Pane>
                 <Pane prefHeight="412.0" prefWidth="1054.0">
                    <children>
                       <TableView fx:id="tableView" prefHeight="412.0"     
   prefWidth="1054.0">
                         <columns>
                           <TableColumn fx:id="customerid" prefWidth="96.0" 
  text="Customer_ID" />
                             <TableColumn fx:id="table_lastname" 
  prefWidth="96.0" text="Last Name" />
                             <TableColumn fx:id="table_firstname"  
  prefWidth="96.0" text="First Name" />
                               <TableColumn fx:id="table_organization" 
  prefWidth="96.0" text="Organization" />
                             <TableColumn fx:id="table_phone" 
  prefWidth="96.0" text="Phone" />
                              <TableColumn fx:id="table_email" 
  prefWidth="96.0" text="Email" />
                             <TableColumn fx:id="table_address" 
  prefWidth="96.0" text="Address" />
                             <TableColumn fx:id="table_city" 
   prefWidth="96.0" text="City" />
                             <TableColumn fx:id="table_state" 
  prefWidth="96.0" text="State" />
                               <TableColumn fx:id="table_zipcode" 
  prefWidth="96.0" text="Zip Code" />
                           <TableColumn fx:id="table_country" 
   prefWidth="96.0" text="Country" />
                         </columns>
                       </TableView>
                    </children>
                 </Pane>
              </children>
           </Pane>
        </children>
        </GridPane>
    </VBox>
  </HBox>
  </VBox>

这是我的客户类别

package wonder.wondercakecis3368project;

 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 javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import javax.swing.text.TabableView;
import java.util.Objects;

@Entity
@Table(name = "Customer")

public class Customer {
private int customerId;
private String firstName;
private String lastName;
private String organizationName;
private String phone;
private String email;
private String streetAddress;
private String postalCode;
private String city;
private String state;
private String country;


   public Customer(String lastname, String firstname, String             
organizationname,     String Phone, String Email,String City, String State, 
String postalcode, String     Country) {
    lastName =  lastname;
    firstName = firstname;
    this.organizationName = organizationname;
    this.phone = Phone;
    this.email = Email;
    this.city = City;
    this.state = State;
    this.postalCode = postalcode;
    this.country = Country;
}
//
//    TableView <Customer> tableView = new TableView<Customer>();
 //
    //    private final ObservableList<Customer> CustomerList         

=FXCollections.<Customer>observableArrayList(new Customer     
(input_lastname.getText    
(),firstName,organizationName,phone,email,city,state,postalCode,country));

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "customer_id", nullable = false)
public int getCustomerId() {
    return customerId;
}

public void setCustomerId(int customerId) {
    this.customerId = customerId;
}

@Basic
@Column(name = "first_name", nullable = true, length = 50)
public String getFirstName() {
    return firstName;
}

public void setFirstName(String firstName) {
    this.firstName = firstName;
}

@Basic
@Column(name = "last_name", nullable = true, length = 50)
public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

@Basic
@Column(name = "organization_name", nullable = true, length = 255)
public String getOrganizationName() {
    return organizationName;
}

public void setOrganizationName(String organizationName) {
    this.organizationName = organizationName;
}

@Basic
@Column(name = "phone", nullable = true, length = 26)
public String getPhone() {
    return phone;
}

public void setPhone(String phone) {
    this.phone = phone;
}

@Basic
@Column(name = "email", nullable = true, length = 255)
public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

@Basic
@Column(name = "street_address", nullable = true, length = 100)
public String getStreetAddress() {
    return streetAddress;
}

public void setStreetAddress(String streetAddress) {
    this.streetAddress = streetAddress;
}

@Basic
@Column(name = "postal_code", nullable = true, length = 12)
public String getPostalCode() {
    return postalCode;
}

public void setPostalCode(String postalCode) {
    this.postalCode = postalCode;
}

@Basic
@Column(name = "city", nullable = true, length = 60)
public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

@Basic
@Column(name = "state", nullable = true, length = 55)
public String getState() {
    return state;
}

public void setState(String state) {
    this.state = state;
}

@Basic
@Column(name = "country", nullable = true, length = 55)
public String getCountry() {
    return country;
}

public void setCountry(String country) {
    this.country = country;
}

   @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Customer customer = (Customer) o;
    return customerId == customer.customerId &&
            Objects.equals(firstName, customer.firstName) &&
            Objects.equals(lastName, customer.lastName) &&
            Objects.equals(organizationName, customer.organizationName) &&
            Objects.equals(phone, customer.phone) &&
            Objects.equals(email, customer.email) &&
            Objects.equals(streetAddress, customer.streetAddress) &&
            Objects.equals(postalCode, customer.postalCode) &&
            Objects.equals(city, customer.city) &&
            Objects.equals(state, customer.state) &&
            Objects.equals(country, customer.country);
}

@Override
public int hashCode()    return Objects.hash(customerId, 
firstName,  lastName,organizationName,     phone, email, streetAddress, 
  postalCode, city, state, country);
  }


}

0 个答案:

没有答案