Layui form of table data interface requests prompt abnormality Solution

Layui form of table data interface requests prompt abnormality

Because I was new to Layui this framework, then look at the official documentation for the return type of interface data interpretation, I was ignorant, and I thought it was a simple Json data format, and later read a lot of articles on Gangster msdn, finally understood its return data type is a message header + Json data format
Here Insert Picture Description
backstage pass over the data is roughly like this:

 { UserJson=[{
  "msg":"ok",
  "code":0,
  "count":4,
  "data":[
                  {"id":1,"password":"123456","userName":"aa"},
                 {"id":2,"password":"123456","userName":"bb"},
                 {"id":3,"password":"123456","userName":"cc"},
                {"id":5,"password":"123456","userName":"ee"}
            ]
 }]
}

The reason a lot of people appear interface errors, many of which are due to return data format does not lead to,

Here is my solution:

List<User> users =us.getAllUsers();
			Gson gson =new Gson();
			String userString=gson.toJson(users);//先将得到的集合Users转化成json字符串
			String userInfo="{\"code\":\"0\",\"msg\":\"ok\",\"count\":1,\"data\":"+userString+"}";
			//用了一个字符串拼接的方式,使返回的数据变成Layui的支持的数据类型

Attach screenshots of successfully acquired:
Here Insert Picture Description
If you have questions, please point out
the novice white
we progress together

Published 12 original articles · won praise 17 · views 2988

Guess you like

Origin blog.csdn.net/qq1140037586/article/details/104643925