返回的数据不符合规范,正确的成功状态码 (code) 应为:0

在这里插入图片描述

Spring 整合 layui 报错 后台代码

package com.jakcray.springbootshiro.manage;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jakcray.springbootshiro.controller.TestController;
import com.jakcray.springbootshiro.mybatisutils.dao.UserDAO;
import com.jakcray.springbootshiro.mybatisutils.dao.UserDAOExample;
import com.jakcray.springbootshiro.mybatisutils.mapper.UserDAOMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {


    @Autowired
    UserDAOMapper userDAOMapper;


    private static final Logger logger = LoggerFactory.getLogger(UserController.class.getName());


    //根据ID公司来查询权限
    @RequestMapping(value = "/getManagers" ,method = RequestMethod.POST)
    public List<UserDAO> getManagers(){

        UserDAOExample ude = new UserDAOExample();
        ude.createCriteria().andIduserIsNotNull();
        List<UserDAO> userDAOS = userDAOMapper.selectByExample(ude);
        //现在是查询所有的用户,之后如果有权限设置之后应该查询  对应的部门的用户的管理员
        String s = JSON.toJSONString(userDAOS);
        logger.info(s);
        return userDAOS;
    }
}

网上查询说是 放回的json格式不对。。
原来是返回的格式真心不对哈哈。。
因为layui接受的数据个是如下:

response: { //定义后端 json 格式,详细参见官方文档
            code: 0,
            msg: "",
            count: 1000,
            data: []
       }

按照此格式定义对象即可修改之后的代码如下:

package com.jakcray.springbootshiro.manage;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jakcray.springbootshiro.controller.TestController;
import com.jakcray.springbootshiro.mybatisutils.dao.UserDAO;
import com.jakcray.springbootshiro.mybatisutils.dao.UserDAOExample;
import com.jakcray.springbootshiro.mybatisutils.mapper.UserDAOMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {


    @Autowired
    UserDAOMapper userDAOMapper;


    private static final Logger logger = LoggerFactory.getLogger(UserController.class.getName());


    //根据ID公司来查询权限
    @RequestMapping(value = "/getManagers" ,method = RequestMethod.POST)
    public String getManagers(){

        UserDAOExample ude = new UserDAOExample();
        ude.createCriteria().andIduserIsNotNull();
        List<UserDAO> userDAOS = userDAOMapper.selectByExample(ude);
        //现在是查询所有的用户,之后如果有权限设置之后应该查询  对应的部门的用户的管理员
        String s = JSON.toJSONString(userDAOS);
        logger.info(s);

        JSONObject obj=new JSONObject();
        //前台通过key值获得对应的value值
        obj.put("code", 0);
        obj.put("msg", "");
        obj.put("count",1000);
        obj.put("data",userDAOS);
        return obj.toJSONString();
    }
}

参照地址如下

  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值