Trp_Cys 2023-08-26 22:19 采纳率: 58.6%
浏览 99

用Postman测试后端数据返回值为null

DeptController.java

// 部门管理
@RestController
@Slf4j
public class DeptController {
    //private static Logger log = LoggerFactory.getLogger(DeptController.class);

    @Autowired
    private DeptService deptService;

    //@RequestMapping(value = "/depts",method = RequestMethod.GET)   // 请求方式为GET
    @GetMapping("/depts")
    public Result list(){
        log.info("查询全部部门数据:");
        //调用service查询部门数据
        List<Dept> deptList =  deptService.list();
        return Result.success(deptList);
    }
}

DeptMapper.java

// 部门管理
@Mapper
public interface DeptMapper {
    // 查询全部部门信息
    @Select("select * from dept")
    List<Dept> list();
}

表Dept的数据:

img

实体类Dept.java

// 部门实体类
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Dept {
    private Integer id; //ID
    private String name; //部门名称
    private LocalDateTime createTime; //创建时间
    private LocalDateTime updateTime; //修改时间
}

接口DeptService及其实现DeptServiceImpl

// 部门管理
@Service
public interface DeptService {

    List<Dept> list();
}

package com.wangchen.service.impl;

import com.wangchen.mapper.DeptMapper;
import com.wangchen.pojo.Dept;
import com.wangchen.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> list() {
        return deptMapper.list();
    }
}

测试结果:

img

为什么表Dept中明明有数据,为什么data的返回结果为null?

  • 写回答

2条回答 默认 最新

  • 小明爱吃火锅 2023-08-26 23:05
    关注

    调试看一下,控制层接口有没有这个有数据返回吗?
    有的话 说明你的result封装有问题。
    看一下你的Result类

    评论

报告相同问题?

问题事件

  • 创建了问题 8月26日