0

提交表单后,我在控制台(角度部分)中获取值,但在我的 Spring Boot 应用程序中,除了名字、姓氏、日期、年龄、地址和语言之外,所有值都为空。有人可以建议做错了什么。

详细信息-form.component.ts

import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import {
  FormArray,
  FormBuilder,
  FormControl,
  FormGroup,
  Validators,
} from '@angular/forms';
import { MatTableDataSource } from '@angular/material/table';
import { PatientDetails } from '../models/PatientDetails.model';
import { PatientService } from '../services/patient.service';
import { AllergyDetails } from '../models/AllergyDetails.model';
// import { allergy } from '../model/allergy';

export interface Allergy {
  allergy_id: string;
  allergy_name: string;
  allergy_Type: number;
  allergy_Description: string;
  allergy_clinicalInfo: string;
}

export interface Allergies {
  value: string;
  display: string;
}
export interface AllergiesType {
  value: string;
  display: string;
}
export interface AllergiesName {
  value: string;
  display: string;
}
@Component({
  selector: 'app-details-form',
  templateUrl: './details-form.component.html',
  styleUrls: ['./details-form.component.css'],
})
export class DetailsFormComponent implements OnInit {
  IsSelected: boolean = false;
  addressForm = this.fb.group({
    company: null,
    title: [null, Validators.required],
    firstName: [null, [Validators.required,Validators.minLength(2)]],
    lastName: [null, [Validators.required,Validators.minLength(2)]],
    date:[null,Validators.required],
    age:[null,Validators.required],
    address: [null, Validators.required],

    Choose: [null, Validators.required],
    languages:[null, Validators.required],
    Gender: [null, Validators.required],
    
    Phone: [null, [Validators.required,Validators.pattern("^[0-9]*$"),
    Validators.maxLength(10),Validators.minLength(10)]],
    Email: [null, [Validators.required,Validators.email]],
    Ethinicity: [null, Validators.required],
    Race: [null, Validators.required],
    EfirstName: [null, [Validators.required,Validators.minLength(2)]],
    ElastName: [null, [Validators.required,Validators.minLength(2)]],
    Relationship: [null, Validators.required],
    EEmail: [null,  [Validators.required,Validators.email]],
    EPhone: [null, [Validators.required,Validators.pattern("^[0-9]*$"),
    Validators.maxLength(10),Validators.minLength(10)]],
    Eaddress: [null, Validators.required],
    allergy_id: [null, Validators.required],
    allergy_name: [null, Validators.required],
    allergy_Type: [null, Validators.required],
    allergy_Description: [null, Validators.required],
    allergy_clinicalInfo: [null, Validators.required],

  });



  hasUnitNumber = false;

  states = [
    { name: 'Maharashtra', abbreviation: 'MH' },
    { name: 'Odisha', abbreviation: 'OD' },
    { name: 'Andhra Pradesh', abbreviation: 'AP' },
    { name: 'Uttar Pradesh', abbreviation: 'UP' },
  ];

  Relationships = [
    { name: 'Father', abbreviation: 'Father' },
    { name: 'Mother', abbreviation: 'Mother' },
    { name: 'Sibling', abbreviation: 'Sibling' },
    { name: 'Friend', abbreviation: 'Friend' },
  ];

  selectedValue: string | null = null;
  Allergy: Allergies[] = [
    { value: 'Allergy1', display: 'Allergy1' },
    { value: 'Allergy2', display: 'Allergy2' },
    { value: 'Allergy3', display: 'Allergy3' }
  ];
  selectedTypeValue: string | null = null;
  Allergytype: AllergiesType[] = [
    { value: 'Food Borne', display: 'Food Borne' },
    { value: 'Water Borne', display: 'Water Borne' },
    { value: 'Air Borne', display: 'Air Borne' },
    { value: 'Other', display: 'Other' },
  ];
  AllergyName: AllergiesName[] = [
    { value: 'Norovirus', display: 'Norovirus' },
    { value: 'Salmonella', display: 'Salmonella' },
    { value: 'Campylobacter', display: 'Campylobacter' },
    { value: 'Listeria', display: 'Listeria' },

    { value: 'Diarrhea', display: 'Diarrhea' },
    { value: 'Cholera', display: 'Cholera' },
    { value: 'Typhoid', display: 'Typhoid' },
    { value: 'Hepatitis', display: 'Hepatitis' },

    { value: 'Coronavirus', display: 'Coronavirus' },
    { value: 'Common cold', display: 'Common cold' },
    { value: 'Influenza', display: 'Influenza' },
    { value: 'Mumps', display: 'Mumps' },
    { value: 'Measles', display: 'Measles' },
  ];
  nameOfAllergy: string | null = null;
  descriptionOfAllergy: string | null = null;
  clinicalInformationOfAllergy: string | null = null;

  displayedColumns: string[] = [
    'allergy_id',
    'allergy_name',
    'allergy_Type',
    'allergy_Description',
    'allergy_clinicalInfo',
    'Action'
  ];
  dataSource : MatTableDataSource<Allergy> 
  router: any;
  maxDate: Date;
  d: any;
  constructor(private fb: FormBuilder, private fc: FormBuilder, private patientService: PatientService) { 

    const ob : Allergy[]=[];
    this.dataSource = new MatTableDataSource(ob);

    const max = new Date();
    
    this.maxDate = new Date(max);
  }
  ngOnInit() {

  }

  addForm() {
    this.dataSource.data.push({
      allergy_id: this.addressForm.value.allergy_id,
      allergy_name: this.addressForm.value.allergy_name,
      allergy_Type: this.addressForm.value.allergy_Type,
      allergy_Description: this.addressForm.value.allergy_Description,
      allergy_clinicalInfo: this.addressForm.value.allergy_clinicalInfo


    });
    this.addressForm.reset();
    this.dataSource.filter="";
  }

    

    remove(index: number) {
        
      this.dataSource.data.splice(index,1);
  
      this.dataSource.filter="";
    }

  onSubmit(): void {
    

    const ob= new PatientDetails(this.addressForm.value.title,
      this.addressForm.value.firstName,
      this.addressForm.value.lastName,
      this.addressForm.value.address,
      this.addressForm.value.Phone,
      this.addressForm.value.Email,
      this.addressForm.value.date,
      this.addressForm.value.age,
      this.addressForm.value.Ethinicity,
     this.addressForm.value.Gender,
     this.addressForm.value.Race,
     this.addressForm.value.languages,
      this.addressForm.value.EfirstName,
      this.addressForm.value.ElastName,
      this.addressForm.value.Relationship,
      this.addressForm.value.EEmail,
      this.addressForm.value.EPhone,
      this.addressForm.value.Eaddress  
    );

    this.patientService.addPatientDetails(ob).subscribe();

  }
  onCheckboxClick(): boolean {
    this.IsSelected = !this.IsSelected;
    this.selectedTypeValue = null;
    this.selectedValue = null;
    this.clinicalInformationOfAllergy = null;
    this.nameOfAllergy = null;
    this.descriptionOfAllergy = null;
    return this.IsSelected;
  }
  selectedValuechange() {
    if (this.selectedValue == "Allergy1") {
      this.selectedTypeValue = "Food Borne";
      this.clinicalInformationOfAllergy = "Less Dangerous";
      this.nameOfAllergy = "Listeria";
      this.descriptionOfAllergy = "It is a food borne disease.";
    }
    else if (this.selectedValue == "Allergy2") {
      this.selectedTypeValue = "Water Borne";
      this.clinicalInformationOfAllergy = "Dangerous";
      this.nameOfAllergy = "Cholera";
      this.descriptionOfAllergy = "It is a Water borne disease.";
    }
    else if (this.selectedValue == "Allergy3") {
      this.selectedTypeValue = "Air Borne";
      this.clinicalInformationOfAllergy = " very Dangerous";
      this.nameOfAllergy = "Measles";
      this.descriptionOfAllergy = "It is a Air borne disease.";
    }
    else {
      this.selectedTypeValue = null;
      this.clinicalInformationOfAllergy = null;
      this.nameOfAllergy = null;
      this.descriptionOfAllergy = null;
    }
  }
  selectedTypechange() {
    if (this.selectedTypeValue == "Food Borne") {
      this.clinicalInformationOfAllergy = "Less Dangerous";
      this.nameOfAllergy = "Dengue";
      this.descriptionOfAllergy = null;
    }
    else if (this.selectedTypeValue == "Water Borne") {
      this.clinicalInformationOfAllergy = "Dangerous";
      this.nameOfAllergy = "Diarrhoea";
      this.descriptionOfAllergy = null;
    }
    else if (this.selectedTypeValue == "Air Borne") {
      this.clinicalInformationOfAllergy = " very Dangerous";
      this.nameOfAllergy = "COVID-19";
      this.descriptionOfAllergy = null;
    }
    else if (this.selectedTypeValue == "Other") {
      this.clinicalInformationOfAllergy = null;
      this.nameOfAllergy = null;
      this.descriptionOfAllergy = null;
    }
    else {
      this.selectedTypeValue = null;
      this.clinicalInformationOfAllergy = null;
      this.nameOfAllergy = null;
      this.descriptionOfAllergy = null;
    }
  }
  selectedNamechange() {

  }
  
  selectDateValue: Date | null=null;
  AgeOf : number| null=null;
  selectDate(){

   // console.log("here");
    this.selectDateValue = this.addressForm.value.date;
    var birthYear = this.selectDateValue!.getFullYear();
    
    var presentYear = new Date().getFullYear();
    var x = presentYear - birthYear;
    //this.addressForm.value.Age = age;
    this.AgeOf = x;
}


IsSame:any;
IsSameAddress:any;
checkAddress()
{
  if(this.IsSame=="Yes")
  {
      this.IsSameAddress=this.addressForm.get('address')?.value;

  }
  else{
        this.IsSameAddress=null;
  }

}
  
  }

PatientDetails.model.ts

import { ThrowStmt } from '@angular/compiler';
import { sample } from 'rxjs/operators';
import { Allergy } from '../details-form/details-form.component';
//import * as internal from 'stream';

export class PatientDetails {
  public title: string;
  public firstName: string;
  public lastName: string;
  public address: string;
  public date : Date;
  public age!:Number;
   public Phone: string;
  public Email: string;
  public Ethinicity: string 
  public Gender: string;
  public languages:string;

  public Race: string;
  public EfirstName: string;
  public ElastName: string;
  public Relationship: string;

  public EEmail: string;
  public EPhone: string;
  public Eaddress: String;

  
  

  // public allergy_id!: string;
  // public allergy_name!: string;
  // public allergy_Description!: String;
  // public allergy_clinicalInfo!: string;

  constructor(
    title: string,
    firstName: string,
    lastName: string,
    address: string,
    Phone: string,
    Email: string,
    date: Date,
    age:Number,
    
    
    Ethinicity: string,
    Gender: string,
    Race: string,
    languages:string,
    
    EfirstName: string,
    ElastName: string,
    Relationship:string,
    EEmail: string,
    EPhone: string,
    Eaddress: string,
    
  ) {
    this.title = title;
    this.firstName = firstName;
    this.lastName = lastName;
    this.address = address;
    this.date=date;
    this.age=age;
    this.Phone = Phone;
    this.Email = Email;
    this.Ethinicity = Ethinicity;
    this.Gender = Gender;
    this.languages=languages;
    this.Race = Race;
    this.EfirstName = EfirstName;
    this.ElastName = ElastName;
    this.Relationship= Relationship;
    this.EEmail = EEmail;
    this.EPhone = EPhone;
    this.Eaddress = Eaddress;
  }
}

病人服务.ts

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Allergy } from '../details-form/details-form.component';
import { AllergyDetails } from '../models/AllergyDetails.model';
import { PatientDetails } from '../models/PatientDetails.model';



@Injectable({ providedIn: 'root' })
export class PatientService {
  

  details : PatientDetails[]=[];

  
  addPatientDetails(ob: PatientDetails) {

    console.log('Added Successfully');
    console.log(ob.Phone);
    console.log(ob.Gender);
    console.log(ob.Race);
    return this.http.post('http://localhost:8080/user/details ',ob,{responseType : 'json' as 'text'});
    
    }

    

  


    
    
  
  constructor(private http: HttpClient) {}

  

 
}

春季启动

PatientDetails.java

package com.CTHospital.PatientDetails.Models;

import javax.persistence.*;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;

@Entity
@Table(name ="ct_patient_details")
public class PatientDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)

    private Integer patient_id;

    @Column(name = "title")
    private String title;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;

    @Column(name = "home_address")
    private String address;

    @Column(name = "contact_number")
    private String Phone;

    @Column(name = "email")
    private String Email;

    @Column(name = "date")
    private Date date;

    @Column(name = "age")
    private Integer age;

    @Column(name = "ethnicity")
    private String Ethinicity;

    @Column(name = "gender")
    private String Gender;

    @Column(name = "race")
    private String Race;

    @Column(name = "languages")
    private String languages;

    @Column(name = "emergency_contact_first_name")
    private String EfirstName;

    @Column(name = "emergency_contact_last_name")
    private String ElastName;

    @Column(name = "relationship")
    private String Relationship;

    @Column(name = "emergency_contact_email")
    private String EEmail;

    @Column(name = "emergency_contact_no")
    private String EPhone;

    @Column(name = "emergency_contact_address")
    private String Eaddress;

    public PatientDetails( ){

    }

    public PatientDetails(Integer patient_id, String title, String firstName, String lastName,
                          String address, String Phone, String Email, Date date, Integer age,
                          String Ethinicity, String Gender, String Race, String languages,
                          String EfirstName, String ElastName, String Relationship, String EEmail,
                          String EPhone, String Eaddress) {
        this.patient_id = patient_id;
        this.title = title;
        this.firstName = firstName;
        this.lastName = lastName;
        this.address = address;
        this.Phone = Phone;
        this.Email = Email;
        this.date = date;
        this.age = age;
        this.Ethinicity = Ethinicity;
        this.Gender = Gender;
        this.Race = Race;
        this.languages = languages;
        this.EfirstName = EfirstName;
        this.ElastName = ElastName;
        this.Relationship = Relationship;
        this.EEmail = EEmail;
        this.EPhone = EPhone;
        this.Eaddress = Eaddress;

    }

    public Integer getPatient_id() {
        return patient_id;
    }

    public void setPatient_id(Integer patient_id) {
        this.patient_id = patient_id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getFirstName() {
        return firstName;
    }

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

    public String getLastName() {
        return lastName;
    }

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

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return Phone;
    }

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

    public String getEmail() {
        return Email;
    }

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

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public String getEthinicity() {
        return Ethinicity;
    }

    public void setEthinicity(String Ethinicity) {
        this.Ethinicity = Ethinicity;
    }

    public String getGender() {
        return Gender;
    }

    public void setGender(String Gender) {
        this.Gender = Gender;
    }

    public String getRace() {
        return Race;
    }

    public void setRace(String Race) {
        this.Race = Race;
    }

    public String getLanguages() {
        return languages;
    }

    public void setLanguages(String languages) {
        this.languages = languages;
    }

    public String getEfirstName() {
        return EfirstName;
    }

    public void setEfirstName(String EfirstName) {
        this.EfirstName = EfirstName;
    }

    public String getElastName() {
        return ElastName;
    }

    public void setElastName(String ElastName) {
        this.ElastName = ElastName;
    }

    public String getRelationship() {
        return Relationship;
    }

    public void setRelationship(String Relationship) {
        this.Relationship = Relationship;
    }

    public String getEEmail() {
        return EEmail;
    }

    public void setEEmail(String EEmail) {
        this.EEmail = EEmail;
    }

    public String getEPhone() {
        return EPhone;
    }

    public void setEPhone(String EPhone) {
        this.EPhone = EPhone;
    }

    public String getEaddress() {
        return Eaddress;
    }

    public void setEaddress(String Eaddress) {
        this.Eaddress = Eaddress;
    }
}

控制器

package com.CTHospital.PatientDetails.Controller;

import com.CTHospital.PatientDetails.Models.PatientDetails;
import com.CTHospital.PatientDetails.Service.PatientDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "*")
public class PatientDetailsController {

    @Autowired
    private PatientDetailsService patientDetailsService;

    @PostMapping("/details")
    public PatientDetails saveDetails(@RequestBody PatientDetails patientDetails)

    {
        System.out.println(patientDetails.getFirstName())//here im getting values 
        System.out.println(patientDetails.getPhone());// getting null here pls help
        System.out.println(patientDetails.getGender());//// getting null here pls help

            return patientDetailsService.saveDetails(patientDetails);

    }

}



服务

package com.CTHospital.PatientDetails.Service;

import com.CTHospital.PatientDetails.Models.PatientDetails;
import com.CTHospital.PatientDetails.Repository.PatientDetailsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PatientDetailsService {

    @Autowired
    private PatientDetailsRepository patientDetailsRepository;

    public PatientDetails saveDetails(PatientDetails patientDetails){

       return  patientDetailsRepository.save(patientDetails);


    }

    }

存储库

package com.CTHospital.PatientDetails.Repository;

import com.CTHospital.PatientDetails.Models.PatientDetails;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Repository
public interface PatientDetailsRepository extends JpaRepository<PatientDetails,Integer> {
}


应用程序属性

spring.datasource.url=jdbc:mysql://localhost:3306/ct-hospital?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
4

0 回答 0