Home > Mobile >  Spring Boot JPA sending information to the front
Spring Boot JPA sending information to the front

Time:01-25

I am working on Spring Boot project that includes reservations. So far, I have made everything to works fine, but I need to send the information to front side about reservations in database. I have rooms, inside rooms I have desks and every desk can have one reservation. Now, my problem is how to list all the reservations, send them to the front side with the info are they occupied or not. When front side see the result of my api to know exactly which desk have reservation, and which not. It is crucial for him to make front part of my application. I read something about @Transient annotation, so can I use something like that?

Thanks!

CodePudding user response:

I see that you are new to stackoverflow; please check the guidance to asking questions: https://stackoverflow.com/help/how-to-ask

Now to answer your question, I think that the best case for you is using rest APIs, when you handle the logic in back-end part (DB side) and return list of your result having a boolean value per example : isOccupied; that indicates the status of the reservation.

" I have rooms, inside rooms I have desks and every desk can have one reservation": I think the challenge here is to do the right relationships (one to many and one to one) and mapping to your entities.

Transient means ignore field in serialization, it can be applied to serialVersionUID for example.

CodePudding user response:

OK, now you want to send the desk status(occupied or not) to the frontend. All you have to do is just simply send the status field and desk id in your database to the frontend.

And you can consider using @JsonIgnoreProperties(value={'fields'}) on your modal class to filter the fields you don't want to send back to frontend.

For example,

@JsonIgnoreProperties({ "id", "systemId" })
class Student {
   public int id;
   public String systemId;
   public int rollNo;
   public String name;

   Student(int id, int rollNo, String systemId, String name){
      this.id = id;
      this.systemId = systemId;
      this.rollNo = rollNo;
      this.name = name;
   }
}

The result will be

{
   "rollNo" : 11,
   "name" : "Mark"
}
  •  Tags:  
  • Related