Request failed with status code 500以及自引用循環Self referencing loop detected for property ‘xx‘ with type


錯誤Error: Request failed with status code 500 ,調試前端沒問題,后端也沒問題,還報錯“連接超時” 在Network中找到錯誤Self referencing loop detected for property 'xxxx' with type

當我們后端調試一步一步調試也沒發現錯誤在哪里,但是跳轉到前端就報錯了。前端沒有接收到后端傳過來的數據,總結了一下:

 

**前端接收問題**
前端就是接收**字段名**以及**類型**問題 比如:nAmE,names,name:0,name:[]等等名字和類型問題

 data() {
    return {
      filter: {
        name: null,
       }}},

    this.axios.get("/api/xxx/xxx").then((res) => {
    可以加一個彈窗看看有沒有跳進來,跳進來了就是前端問題
    alert();
    this.name=res;
    });

**后端問題**

當我們在數據庫里面添加對應表的**外鍵** 並調用 *程序中經常會用到來回調用,或者調用當前的下一級等等場景*

   public class User
    {
       public int id { get; set; }
       public int LoginId { get; set; }
       public Login Logins{ get; set; }
    }
    
   public class User
    {
       public int id { get; set; }
       public int UserId { get; set;}
       public User Users{ get; set; }
    }

在后端處理完后,往前端返回數據的時候

public xxx
{
  var result= user.quer();
   return ok(result)
}

 

這個時候注意一個問題不然就會上述錯誤

//當我們引用   user的時候
                //類里面
           user   ——> id=1  
                      LoginId=1
                      Login =system.Login   //這是一般的時候不會有錯誤,因為LoginId沒有對應的user表
            

就怕這個時候你引用類里面又反過來調用我們的類,形成的邏輯循環

           user   ——> id=1  
                      LoginId=1
                      Login =system.Login   ——>id=1
                                               UserId=1
                                               User=system.User ——>  id=1
                                                                     Login=1
                                                                     Login=system.Login ——> id=1
                                                                                            UserId=1
                                                                                            User=system.User ——>.........
                   //.................以此類推一直循環,但這本身沒有錯誤不會報錯..........................

 

總結:當我們的 user類外鍵鏈接了Login類,而Login類也鏈接了User類,這個時候輸出User類的時候恰好有個LoginId值,使得Login也調用了User,那就會形成自引用循環,就會報錯

 

希望上述能幫到你


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM