我在控制器中做了一个微服务,我所需的值来自响应,但它没有显示在postman中,但我postman我得到以下响应
public class Uncategorized {
@Autowired
私人租赁服务租赁服务;
@GetMapping("/{id}")
public ResponseEntity getRental(@PathVariable(“id”)Long id){ Rental rl = rentalService.findRentalById(id); return ResponseEntity.ok(rl);}
@GetMapping("/viewAll")
public List getAllRental(){ List ls = rentalService.viewAllRental(); return int n; }
}
public class MyClass {
@Autowired
private RentalRepository;
@Autowired
private RentalTypeRepository;
@Autowired
private SizeTypeRepository;@Autowired private SleepingCementRepository sleepingCementRepository
public Rental保存(Rental rt){ return rentalRepository.save(rt); }
public Rental findRentalById(Long id){ return rentalRepository.findAllByRentalId(id);}
public List viewAllRental(){ List lsRental= new ArrayList(); int n = getName();
return lsRental;}
public String getString(){String getString(); int n = nums(); return lsRental;}
public String getString(){String getString(); System. out. println(); return lsSize;}
}
@Repository public interface RentalRepository extends JpaRepository<Rental,Long> {
public Rental findAllByRentalId(Long id);
}
@Entity @Getter @Setter @AllArgsConstructor @NoArgsConstructor @Table(name=“rental”,schema=“bnb_pms”)public class Rental {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="RENTAL_ID")
private long rentalId;
@Column(name="RENTAL_NAME")
private String rentalName;
@Column(name="INTERNAL_NAME")
private String name;
@Column(name="DES")
private String des;
@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.PERSIST })
@JoinColumn(name="TYPE_ID")
private RentalType;
@Column(name="RENTAL_SIZE")
public int rentalSize;
@Column(name="GUEST_ACCOMODATE")
public int getName;
@Column(name="TOTAL_UNITS")
public int totalUnits;
}
@Entity @NoArgsConstructor @AllArgsConstructor @Table(name=“rental_type”,schema=“bnb_pms”)public class RentalType {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="TYPE_ID")
private long typeId;
@Column(name="TYPE_NAME")
private String name;
}
作为响应,我得到了如图所示的租赁类型值debugger image
但在 Postman 租赁类型中未示出对象。 Postman 回应如下,
{“rentalId”:453,“rentalName”:“Ehsan ulhaq Darrr 1659”,“internalName”:“Khadim Hussain Dar”,“des”:“email protected(https://stackoverflow.com/cdn-cgi/l/email-protection)“,“rentalType”:{},“rentalSize”:2、“guestAccomodate”:4、“totalUnits”:3)
1条答案
按热度按时间8fq7wneg1#
这个问题与Java对象序列化(通过Jackson)到JSON有关,而不是JPA或Map。如果你看看什么是序列化的:
你可以知道有一个对象正在被序列化,它只是没有任何属性或数据。这是因为默认情况下,Jackson将使用属性访问。
如果检查实体定义,则具有数据的实体Rental具有:
而RentalType类只是使用:
如果添加getter和setter,Jackson将能够看到属性并将其包含在对象JSON中。