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();
}
}