Как получить прошлые данные без ручного ввода данных с помощью формы angular - PullRequest
0 голосов
/ 09 июля 2020

Я разрабатываю веб-приложение с итоговой карточкой. Я хочу добавить прошлые данные об игроках. Как лучше это сделать. Могу ли я использовать файл csv или xml? Как его использовать? Мой Angular ручная форма и модель пружины приведены ниже. куда я должен поместить файл csv (внутренний или внешний)?

Angular форма

<
                  <div *ngIf="errorMessage" class="alert alert-danger">
                    <button (click)="close()" type="button" aria-hidden="true" class="close">
                      <i class="now-ui-icons ui-1_simple-remove"></i>
                    </button>
                    <span>
                      {{ errorMessage }}
                    </span>
                  </div>

                  <form [formGroup]="playerRegisterForm" (ngSubmit)="playerFormSubmit()">
                    <div class="row">

                      <div class="col-sm-12 col-lg-6">
                        <div class="form-group">
                          <input
                            [class.is-invalid]="playerRegisterForm.get('userName').invalid && playerRegisterForm.get('userName').touched"
                            formControlName="userName" type="text" name="userName" placeholder="User Name"
                            class="form-control" />
                          <div
                            *ngIf="playerRegisterForm.get('userName').invalid &&  playerRegisterForm.get('userName').touched">
                            <small *ngIf="userNameField.errors?.required" class="text-danger">User Name Required</small>
                          </div>
                        </div>
                      </div>


                      <div class="col-sm-12 col-lg-6">
                        <div class="form-group">
                          <input
                            [class.is-invalid]="playerRegisterForm.get('nameWithInitial').invalid && playerRegisterForm.get('nameWithInitial').touched"
                            formControlName="nameWithInitial" type="text" name="userInitialName"
                            placeholder="Name With Initial" class="form-control" />
                          <div
                            *ngIf="playerRegisterForm.get('nameWithInitial').invalid &&  playerRegisterForm.get('nameWithInitial').touched">
                            <small *ngIf="nameWithInitialField.errors?.required" class="text-danger">Name With Initial
                              Required</small>
                          </div>
                        </div>
                      </div>

                      <div class="col-sm-12 col-lg-12">
                        <div class="form-group">
                          <input
                            [class.is-invalid]="playerRegisterForm.get('fullName').invalid && playerRegisterForm.get('fullName').touched"
                            formControlName="fullName" type="text" name="fullName" placeholder="Full Name"
                            class="form-control" />
                          <div
                            *ngIf="playerRegisterForm.get('fullName').invalid &&  playerRegisterForm.get('fullName').touched">
                            <small *ngIf="fullNameField.errors?.required" class="text-danger">Full Name
                              Required</small>
                          </div>
                        </div>
                      </div>

                      <div class="col-sm-12 col-lg-6">
                        <div class="form-group">
                          <input
                            [class.is-invalid]="playerRegisterForm.get('nic').invalid && playerRegisterForm.get('nic').touched"
                            formControlName="nic" type="text" name="NIC" placeholder="NIC Number"
                            class="form-control" />
                          <div *ngIf="playerRegisterForm.get('nic').invalid &&  playerRegisterForm.get('nic').touched">
                            <small *ngIf="nicField.errors?.required" class="text-danger">NIC Number Required</small>
                            <small *ngIf="nicField.errors?.pattern" class="text-danger">Insert Valid NIC Number</small>
                          </div>
                        </div>
                      </div>

                      <div class="col-sm-12 col-lg-6">
                        <div class="form-group">
                          <input
                            [class.is-invalid]="playerRegisterForm.get('contactNumber').invalid && playerRegisterForm.get('contactNumber').touched"
                            formControlName="contactNumber" type="text" name="contactNumber"
                            placeholder="Contact Number" class="form-control" />
                          <div
                            *ngIf="playerRegisterForm.get('contactNumber').invalid &&  playerRegisterForm.get('contactNumber').touched">
                            <small *ngIf="contactNumberField.errors?.required" class="text-danger">Contact Number
                              Required</small>
                            <small *ngIf="contactNumberField.errors?.pattern" class="text-danger">Insert Valid Contact
                              Number</small>
                          </div>
                        </div>
                      </div>

                      <div class="col-sm-12 col-lg-12">
                        <div class="form-group">
                          <input
                            [class.is-invalid]="playerRegisterForm.get('address').invalid && playerRegisterForm.get('address').touched"
                            formControlName="address" type="text" name="address" placeholder="Address"
                            class="form-control" />
                          <div
                            *ngIf="playerRegisterForm.get('address').invalid &&  playerRegisterForm.get('address').touched">
                            <small *ngIf="addressField.errors?.required" class="text-danger">Address
                              Required</small>
                          </div>
                        </div>
                      </div>

                      <div class="col-sm-12 col-lg-6">
                        <div class="form-group">
                          <input
                            [class.is-invalid]="playerRegisterForm.get('email').invalid && playerRegisterForm.get('email').touched"
                            formControlName="email" type="text" name="email" placeholder="Email" class="form-control" />
                          <div
                            *ngIf="playerRegisterForm.get('email').invalid &&  playerRegisterForm.get('email').touched">
                            <small *ngIf="emailField.errors?.required" class="text-danger">Email Address
                              Required</small>
                            <small *ngIf="emailField.errors?.email" class="text-danger">Insert valid
                              email</small>
                          </div>
                        </div>
                      </div>



модель пружины

@Entity
@Table(name = "player")
public class Player {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer playerId;

    /*
     * 1 : Batman, 2 : Baller, 3 : AllRounder
     */
    @NotBlank
    private String specialType;

    @NotNull
    @OneToOne
    @JoinColumn(name = "user_id", referencedColumnName = "user_id")
    private User userId;

    @NotNull
    @ManyToOne
    @JoinColumn(name = "baller_type_id", referencedColumnName = "baller_type_id")
    private BallerType ballerTypeId;

    @NotNull
    @ManyToOne
    @JoinColumn(name = "batman_type_id", referencedColumnName = "batman_type_id")
    private BatmanType batmanTypeId;

    @NotNull
    @ManyToOne
    @JoinColumn(name = "club_id", referencedColumnName = "club_id")
    private Club clubId;

    public Player() {
    }

    public Player(Integer playerId, @NotNull String specialType, @NotNull User userId,
            @NotNull BallerType ballerTypeId, @NotNull BatmanType batmanTypeId, @NotNull Club clubId) {
        super();
        this.playerId = playerId;
        this.specialType = specialType;
        this.userId = userId;
        this.ballerTypeId = ballerTypeId;
        this.batmanTypeId = batmanTypeId;
        this.clubId = clubId;
    }

    
    @Override
    public String toString() {
        return "Player [playerId=" + playerId + ", specialType=" + specialType + ", userId=" + userId
                + ", ballerTypeId=" + ballerTypeId + ", batmanTypeId=" + batmanTypeId + ", clubId=" + clubId + "]";
    }

...