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

2023-06-12,,

错误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,那就会形成自引用循环,就会报错

希望上述能帮到你

Request failed with status code 500以及自引用循环Self referencing loop detected for property ‘xx‘ with type的相关教程结束。

《Request failed with status code 500以及自引用循环Self referencing loop detected for property ‘xx‘ with type.doc》

下载本文的Word格式文档,以方便收藏与打印。