Java 未记录参考等级的数据,';空';创建后
我有一个叫做RoomDetailDto的课程,如下所示Java 未记录参考等级的数据,';空';创建后,java,json,spring,rest,dto,Java,Json,Spring,Rest,Dto,我有一个叫做RoomDetailDto的课程,如下所示 public class RoomDetailDto { String ID; @NotEmpty String cd; @NotEmpty String name; String dscp; RoomCategoryDto roomCategoryDto; //setter and getter RoomCategoryTo参考另一个名为RoomCategoryTo的DTO,如下所示: public class RoomC
public class RoomDetailDto {
String ID;
@NotEmpty
String cd;
@NotEmpty
String name;
String dscp;
RoomCategoryDto roomCategoryDto;
//setter and getter
RoomCategoryTo参考另一个名为RoomCategoryTo的DTO,如下所示:
public class RoomCategoryDto {
String ID;
@NotEmpty
@Length(min = 0, max = 5)
String cd;
@NotEmpty
String name;
@NotEmpty
@NumberValue
String cost;
String dscp;
//setter and getter
@RequestMapping(value = "/updateAction", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public RoomDetailDto update(@Validated @RequestBody RoomDetailDto data) throws ParseException, RecordNotFoundException, java.text.ParseException {
logger.info("add");
RoomDetailEntity add = roomDetailService.updateRoomDetail(convertToEntity(data));
return convertToDto(add);
}
我将此JSON发送到服务器
{
“cd”:“dfs23”,
“名称”:“df223”,
“dscp”:“sfdsfs”,
“RoomCategoryTo”:{
“cd”:“KLS2”,
“名称”:“Kelas 2”,
“成本”:“200000”,
“dscp”:空,
“id”:“7f554d7a-3c5d-4c15-921d-fa4b4c629e6c”
}
}
发送到服务器后,该记录已成功插入,但myRoomCategoryTo为“空”
{
“cd”:“dfs23”,
“名称”:“df223”,
“dscp”:“sfdsfs”,
“RoomCategoryTo”:空,
“id”:“ed22b38d-2bc3-4c80-b035-8936318c90c7”
}
有人能给我建议吗?
请按以下方式查找我的控制器:
public class RoomCategoryDto {
String ID;
@NotEmpty
@Length(min = 0, max = 5)
String cd;
@NotEmpty
String name;
@NotEmpty
@NumberValue
String cost;
String dscp;
//setter and getter
@RequestMapping(value = "/updateAction", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public RoomDetailDto update(@Validated @RequestBody RoomDetailDto data) throws ParseException, RecordNotFoundException, java.text.ParseException {
logger.info("add");
RoomDetailEntity add = roomDetailService.updateRoomDetail(convertToEntity(data));
return convertToDto(add);
}
我的实体如下
@Entity(name = "RoomCategoryEntity") @Table(name = "t_room_category") public class RoomCategoryEntity implements Serializable {
public static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Column(name = "ID", unique = true)
private String ID;
@Column(name = "cd")
private String cd;
@Column(name = "name")
private String name;
@Column(name = "cost")
private String cost;
@Column(name = "dscp")
private String dscp;
@Column(name = "createDate")
private Date createDate;
@Column(name = "updateDate")
private Date updateDate;
@Column(name = "isDel")
private Date isDel; //setter and getter}
==================================================================
@Entity(name = "RoomDetailEntity") @Table(name = "t_room_details") public class RoomDetailEntity implements Serializable {
public static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
@Column(name = "ID", unique = true)
private String ID;
@Column(name = "cd")
private String cd;
@Column(name = "name")
private String name;
@Column(name = "dscp")
private String dscp;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "room_category_id", referencedColumnName = "ID")
private RoomCategoryEntity roomCategoryEntity;
@Column(name = "createDate")
private Date createDate;
@Column(name = "updateDate")
private Date updateDate;
@Column(name = "isDel")
private Date isDel;
我刚刚尝试将引用表更改为实体,并成功插入
public class RoomDetailDto {
String ID;
@NotEmpty
String cd;
@NotEmpty
String name;
String dscp;
// I change below line
RoomCategoryEntity roomCategoryEntity;
[
{
“cd”:“df23”,
“名称”:“df23”,
“dscp”:“sfdsfs”,
“房间类别实体”:{
“cd”:“KLS2”,
“名称”:“Kelas 2”,
“成本”:“200000”,
“dscp”:空,
“createDate”:1497535268000,
“updateDate”:空,
“isDel”:空,
“id”:“7f554d7a-3c5d-4c15-921d-fa4b4c629e6c”
},
“id”:“02c28356-9783-46a7-8ac5-9e00497d9be2”
}
]