搞了2天了,就这个接口请求不到数据,其他的都正常。

就是一个前端页面请求数据怎么都不行,我的其他页面都能正常请求:
后端代码:

public R getAddMainList(UserCheckParam userCheckParam) {
        try {
            QueryWrapper<Main> queryWrapper = new QueryWrapper<>();
            queryWrapper.in("add_type", 1, 2)
                    .and(wrapper -> wrapper.isNull("is_delete")
                            .or().ne("is_delete", 1))
                    .and(wrapper -> wrapper.isNull("is_sure")
                            .or().in("is_sure", 0, 1, 2));
            List<Main> mainList = mainMapper.selectList(queryWrapper);
            //根据main表上面的添加类型信息,判断是添加的  并且未被删除  并且未被确认过的 信息
            List<MainAllView> mainAllViewList = new ArrayList<>();
            for (Main main : mainList) {
                QueryWrapper<MainAllView> wrapper = new QueryWrapper<>();
                wrapper.eq("unique_number", main.getUniqueNumber());
                wrapper.eq("faculty", userCheckParam.getFaculty());
                List<MainAllView> list = mainAllViewViewService.selectList(wrapper);
                mainAllViewList.addAll(list);
            }
            //todo:修改。。去视图哪里查询 获得课程信息等待,理论上应该分别查询表的 偷懒了
            List<userDoInfo> userDoInfoList = mainAllViewList.stream()
                    .map(mainAllView -> {
                        userDoInfo userDoInfo = new userDoInfo();
                        //设置特殊情况默认值
                        userDoInfo.setIsFirst(0);
                        userDoInfo.setIsDoubleLanguage(0);
                        userDoInfo.setIsWeekend(0);
                        QueryWrapper<AdditionalMain> additionalMainWrapper = new QueryWrapper<>();
                        additionalMainWrapper.eq("additional_id", mainAllView.getUniqueNumber());
                        AdditionalMain additionalMain = additionalMainService.getOne(additionalMainWrapper);
                        //设置 特殊情况
                        if (additionalMain != null) {
                            getUserDoInfo(additionalMain, userDoInfo);
                        }
                        userDoInfo.setUniqueNumber(mainAllView.getUniqueNumber());
                        userDoInfo.setUserName(mainAllView.getUserName());
                        userDoInfo.setClassName(mainAllView.getClassName());
                        userDoInfo.setClassNumber(mainAllView.getClassNumber());
                        userDoInfo.setTeachName(mainAllView.getTeachName());
                        userDoInfo.setPracticalHours(Integer.parseInt(mainAllView.getPracticalHours()));
                        userDoInfo.setTheoreticalHours(Integer.parseInt(mainAllView.getTheoreticalHours()));
                        return getUserDoInfo(additionalMain, userDoInfo);
                    })
                    .collect(Collectors.toList());
            //System.out.println("院长的队列:\n" + userDoInfoList);
            //return R.error().message("接口测试");
            return R.ok().message("有数据的!!!").data("userDoInfoList", userDoInfoList);
        } catch (NullPointerException e) {
            System.out.println("NullPointerException occurred: " + e.getMessage());
            return R.error().message("NullPointerException occurred: " + e.getMessage());
        } catch (NumberFormatException e) {
            System.out.println("NumberFormatException occurred: " + e.getMessage());
            return R.error().message("NumberFormatException occurred: " + e.getMessage());
        } catch (Exception e) {
            System.out.println("An error occurred: " + e.getMessage());
            return R.error().message("An error occurred: " + e.getMessage());
        }
    }

根据Apifox对后端接口进行查询是能查询出数据的:

img

}
前端代码:

<template>
  <el-table ref="tableRef" row-key="date" :data="tableData" style="width: 100%">
    <el-table-column prop="userName" label="姓名" width="" />
    <el-table-column prop="teachName" label="课程名称" width="" />
    <el-table-column prop="className" label="班级名称" width="" />
    <el-table-column prop="classNumber" label="班级人数" width="" />
    <el-table-column prop="theoreticalHours" label="理论学时" width="" />
    <el-table-column prop="practicalHours" label="实验学时" width="" />
    <el-table-column prop="special" label="其他" />

    <el-table-column align="right" width="120">
      <template #default="scope">
        <el-button type="primary" size="small" @click="passClick(scope.$index, scope.row)">通过</el-button>
        <el-button type="primary" size="small" @click="unPassClick(scope.$index, scope.row)">修改</el-button>
      </template>
    </el-table-column>

  </el-table>
</template>
    
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElNotification } from 'element-plus'
import { yAddMain, sureAddMain, abcd } from '@/api/userPlus.js'
import cookie from 'js-cookie'

const router = useRouter()

interface User {
  userName: String
  className: String
  classNumber: String
  teachName: String
  theoreticalHours: string
  practicalHours: String
  special: String
  uniqueNumber: string
  isFirst: String
  isDoubleLanguage: String
  isWeekend: String
}

const tableData = ref<User[]>([])

const Info = ref({
  sole: '',
  userId: '',
  faculty: ''
})


onMounted(async()=> {
  Info.userId = sessionStorage.getItem("userId")
  Info.faculty = sessionStorage.getItem("faculty")
  try {
    const res = await yAddMain(Info)
    console.log(res.message)
    if (res.code == 200) {
      console.log("获取工作量列表:", res)
      //tableData.value = response.data.userDoInfoList
      if (tableData.value === null) {
        ElNotification.success({
          title: '太好了',
          message: '没有需要确认新课申请',
          showClose: false,
        })
      }
    } else {
      ElNotification.error({
        title: '!!查询数据异常',
        message: res.message,
        showClose: false,
      })
    }
  } catch (error) {
    console.error('请求错误:', error)
    console.trace()
    console.log('%cerror stack trace', 'color: #bada55; font-size: 16px', error.stack)
  if (error.stack) {
    console.error('错误堆栈:', error.stack)
  } else {
    console.error('错误没有堆栈信息。')
  }
    ElNotification.error({
      title: '查询数据异常!!!!!!!',
      message: error,
      showClose: false,
    })
  }
})

// //通过
// const passClick = (index: number, row: User) => {
//   console.log('data:', row)
//   Info.sole = row.uniqueNumber
//   sureAddMain(Info)
//     .then(res => {
//       if (res.code == 200) {
//         console.log("同意成功!")
//       }
//     })
// }

// //修改
// const unPassClick = (index: number, row: User) => {
//   console.log('要修改的课程信息:', row)
//   router.push({
//     path: '/reviseForm',
//     query: {
//       teachName: row.teachName,
//       className: row.className,
//       userName: row.userName,
//       uniqueNumber: row.uniqueNumber,
//       classNumber: row.classNumber,
//       theoreticalHours: row.theoreticalHours,
//       practicalHours: row.practicalHours,
//       isFirst: row.isFirst,
//       isDoubleLanguage: row.isDoubleLanguage,
//       isWeekend: row.isWeekend,
//     }
//   })
// }


</script>


代码运行结果:

img

img

img


info是获取用户权限还是信息的:

img


网络的,红色的,数据请求响应:

img

备注:前端是用来element-plus框架加vue3.
后端就是普通的微服务形式。

附件:
前端页面菜单的代码截图:

img

前端路由截图:

img

axios截图:

img

请求封装:

img

感觉又可能是后端的问题。
代码

QueryWrapper<Main> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("add_type", 1, 2)
                .and(wrapper -> wrapper.isNull("is_delete")
                        .or().ne("is_delete", 1))
                .and(wrapper -> wrapper.isNull("is_sure")
                        .or().in("is_sure", 0, 1, 2));
        List<Main> mainList = mainMapper.selectList(queryWrapper);
//这样直接返回的话,前端能接收到数据,

要是加了后面这段代码。又不行了。


```java
 QueryWrapper<Main> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("add_type", 1, 2)
                .and(wrapper -> wrapper.isNull("is_delete")
                        .or().ne("is_delete", 1))
                .and(wrapper -> wrapper.isNull("is_sure")
                        .or().in("is_sure", 0, 1, 2));
        List<Main> mainList = mainMapper.selectList(queryWrapper);
        System.out.println("List\n");
        System.out.println(mainList);

        List<MainAllView> mainAllViewList = new ArrayList<>();
        for (Main main : mainList) {
            QueryWrapper<MainAllView> wrapper = new QueryWrapper<>();
            wrapper.eq("unique_number", main.getUniqueNumber());
            wrapper.eq("faculty", userCheckParam.getFaculty());
            List<MainAllView> list = mainAllViewViewService.selectList(wrapper);
            mainAllViewList.addAll(list);
        }
        System.out.println("list\n");
        System.out.println(mainAllViewList);

        return R.ok().data("list",mainAllViewList);
//加了这段的话,就会报上面那个异常,前端接收不到东西。可是后端也没有报错

而且接口也确实能返回数据出去。我打印了两个list,格式都是一样的。求指点一下

接口测试有数据,前端换个接口(数据不完全相同)能渲染出来(部分数据)。后端没有错误、数据都是list、测试工具显示有数据、可是后端加多一层查询、前端就报异常、不加(数据无效)前端正常接收(虽然没什么用就是了)。

network里看看 接口 通了没。首先前端要没报错,network里状态也得是200才行

Apifox都有数据 那这就是前端代码有问题 从返回数据那块 一点点排查吧