亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

發布到 restController 時不支持內容類型

發布到 restController 時不支持內容類型

慕勒3428872 2023-06-08 17:38:06
這個問題只發生在這個控制器上,因為我在模型中添加了一個自我關系。我在其他帖子和谷歌中閱讀和搜索,任何解決方案似乎都有效。我嘗試設置@JsonIdentityInfo,添加@JsonBackReference 和@JsonManagedReference,顛倒這個標簽的順序,將消耗添加到 rest 方法,但一切正常模型:@Entity@JsonIdentityInfo(  generator = ObjectIdGenerators.PropertyGenerator.class,   property = "code")@Table (name = "EP7_TRS_CODIGOS")public class Code implements Serializable {    private static final long serialVersionUID = 2L;    @Id    @Column (name = "COD_CODIGO")    private String code;    @Column (name = "DES_CODIGO")    private String description;    @Column (name = "COD_TIPO")    private String type;    @JsonManagedReference    @ManyToOne    @JoinColumn (name = "ID_ORIGEN", referencedColumnName = "ID_ORIGEN")    private Origin origin;    @JsonBackReference    @ManyToOne    @JoinColumn (name="COD_CODIGO_OBJ", referencedColumnName = "COD_CODIGO")    private Code parent;    @JsonManagedReference    @OneToMany (mappedBy = "parent", fetch = FetchType.LAZY)    private List<Code> sons;控制器:@PostMapping(value = "/code",    consumes = MediaType.APPLICATION_JSON_UTF8_VALUE,    produces = {MediaType.APPLICATION_JSON_UTF8_VALUE})public ResponseEntity<Code> saveOrUpdateCode (@RequestHeader HttpHeaders httpHeaders, @RequestBody Code code){    logger.info(">>>> Entra en el controlador saveOrUpdateCode");    if (httpHeaders == null || !authorized(httpHeaders)) {        logger.error(">>>> Error de autentificacion");        return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);    }     return new ResponseEntity<>(cs.save(code), HttpStatus.CREATED);}
查看完整描述

1 回答

?
飲歌長嘯

TA貢獻1951條經驗 獲得超3個贊

您需要在發送 post 請求時添加Content-type帶有值的標頭application/json。另外,你應該@JsonManagedReferenceOrigin課堂上移除。



查看完整回答
反對 回復 2023-06-08
  • 1 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號