【发布时间】:2017-06-17 03:40:21
【问题描述】:
我有一个名为 RoomDetailDto 的 DTO 类,如下所示
public class RoomDetailDto {
String ID;
@NotEmpty
String cd;
@NotEmpty
String name;
String dscp;
RoomCategoryDto roomCategoryDto;
//setter and getter
roomCategoryDto 引用了另一个名为 RoomCategoryDto 的 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
我发送到服务器的这个 JSON
{ "cd":"dfs23", “名称”:“df223”, "dscp":"sfdsfs", "roomCategoryDto":{ "cd":"KLS2", "name":"Kelas 2", “成本”:“200000”, “dscp”:空, “id”:“7f554d7a-3c5d-4c15-921d-fa4b4c629e6c” } }
发送到服务器后,该记录成功插入,但我的 roomCategoryDto 是 'NULL'
{ "cd": "dfs23", “名称”:“df223”, “dscp”:“sfdsfs”, “roomCategoryDto”:空, “id”:“ed22b38d-2bc3-4c80-b035-8936318c90c7” }
谁能给点建议? 请在下面找到我的控制器:
@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;
【问题讨论】: