创建多个实体时发生映射错误

时间:2019-02-04 05:53:22

标签: spring-boot

我需要实现类似于该图像的后端代码。 去压光机那里选择一个日期,然后显示房间名称,地址费用,否 的人,时间,给我提示如何为此场景设置实体。

i have tried like this...location table

 @Entity
 public class Location {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="location_Id")
private long locationId;

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

@JsonManagedReference
@OneToMany(mappedBy="location",cascade=CascadeType.ALL,fetch=FetchType.LAZY)
private List<Calender> calenders=new ArrayList<Calender>();

日历表

@Entity
@Table(name="calender")
public class Calender {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="calenderId")
private long calenderId;

@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
@Column(name="busyDates")
private Date busyDates;

@DateTimeFormat(pattern = "yyyy-MM-dd")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
@Column(name="availableDates")
private Date availableDates;

@JsonBackReference
@ManyToOne
@JoinColumn(name="locationId")
private Location location;

   @OneToMany(mappedBy="calenders",cascade=CascadeType.ALL,fetch=FetchType.LAZY)
    private List<RoomsChecking> roomscheck=new ArrayList<RoomsChecking>();


roomchecking table

@Entity
public class RoomsChecking {

@Id 
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="roomId")
private long roomId;

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

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

@Column(name="cost")
private int cost;

@Enumerated
@Column(name="bookingType")
private BookingType bookingType;

@JsonBackReference
@ManyToOne
@JoinColumn(name="calenderId")
private Calender calenders;

@JsonManagedReference
@OneToMany(mappedBy="roomschecking",cascade=CascadeType.ALL,fetch=FetchType.LAZY)
private List<NoOfPersons> noOfPersons =new ArrayList<NoOfPersons>();

@JsonManagedReference
@OneToMany(mappedBy="roomschecking",cascade=CascadeType.ALL,fetch=FetchType.LAZY)
private List<TimeSlotAvailble> timeslotavl =new ArrayList<TimeSlotAvailble>();

NoOfPersons table

@Entity
public class NoOfPersons {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="personId")
private long personId;

@Column(name="noPersons")
private int noPersons;

@JsonBackReference
@ManyToOne
@JoinColumn(name="roomId")
private RoomsChecking roomschecking;

TimeSlots table


@Entity
public class TimeSlotAvailble {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="timeId")
private int timeId;

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

@JsonBackReference
@ManyToOne
@JoinColumn(name="roomId")
private RoomsChecking roomschecking;



in postman i have sended data like this 
{
"location":"banglore",
"calenders":[{"busyDates": "2019-02-11",
             "availableDates":"2019-02-04",
             "roomscheck":[{
             "roomName":"tirupathi",
             "address" :"address",
             "cost" : 1000,
             "bookingType" :"BOOKINGFORSELF",
             "noOfPersons" :[{"noPersons" :2 ,
             "timeslotavl" :[{"timeSlot":"10:00AM to 12:00AM"}] 
             }]}]}]

}

i get output like this 

{
"locationId": 2,
"location": "banglore",
"calenders": [
    {
        "calenderId": 2,
        "busyDates": "2019-02-11",
        "availableDates": "2019-02-04"
    }
]

}     所有实体相互映射,但不存储所有实体数据。

location entity controller

@RestController
public class LocationContrl {

@Autowired
private LocationService locService;


@PostMapping("/addAccomadation")
public Location addAccDetails(@RequestBody Location location) {
    return locService.addAccDetails(location);
}

location Service

@Service
public class LocationService {

@Autowired
private LocationRep locrep;

public Location addAccDetails(Location location) {
    return locrep.save(location);
}

0 个答案:

没有答案