Uncaught (in promise) Error: Request failed with status code 500

2023-05-16

分享一些状态码400 404 500等原因:
在这里插入图片描述
出错:
在这里插入图片描述
在这里插入图片描述
前端:

 // 获取所有的导航菜单
    async getMenuList(){
      const {data:res} = await this.$http.get("menus");
      console.log(res.data);
      if( res.status != 200) return this.$message.error("操作失败!!!");
      this.menuList = res.data;
    },

后端:

@RestController
public class MenuController {
    @Autowired
    MenuDao menuDao;

    @CrossOrigin
    @RequestMapping("/menus")
    public String getAllMenus(){
        System.out.println("sucess");
        HashMap<String, Object> data = new HashMap<>();
        List<MainMenu> mainMenus = menuDao.getMainMenus();
        data.put("data",mainMenus);
        data.put("status",200);
        String data_json = JSON.toJSONString(data);
        System.out.println("成功访问!!!");
        return data_json;
    }
}

xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.naughty.userlogin02.dao.MenuDao">
    <resultMap id="menumap" type="com.naughty.userlogin02.bean.MainMenu">
        <id column="id"  property="id"></id>
        <result column="title"  property="title"></result>
        <result column="path"  property="path"></result>
        <collection  property="slist" ofType="com.naughty.userlogin02.bean.SubMenu">
            <result column="sid"  property="id"></result>
            <result column="stitle"  property="title"></result>
            <result column="spath"  property="path"></result>
        </collection>
    </resultMap>
    <select id="getMainMenus" resultMap="menumap">
        SELECT mm.*,sm.id as sid ,
               sm.title as stitle,sm.path as spath FROM mainmenu mm ,
           submenu sm WHERE mm.id = sm.mid;
    </select>
 </mapper>

检查后发现是配置文件写错,修改为:

spring:
  datasource:
    #MySQL配置
    driverClassName:  com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3308/data1?useSSL=false&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
    username: heziyi
    password: 123456

修改完后再次启动,没有报错了

错误码404:
发现是因为controller类上面没有加@RestController注解

2.17日又一次出现错误码500
在这里插入图片描述
response报错:

{“timestamp”:“2021-02-17T08:22:46.911+0000”,“status”:500,“error”:“Internal
Server Error”,“message”:“Invalid bound statement (not found):
com.naughty.userlogin02.dao.TeacherDao.getTeacherCounts”,“path”:"/allteacher"}

自己的TeacherDao中有一句话:
public int getTeacherCounts(@Param(“name”) String name);
然后查了一下发现有可能是因为xml中没有对应的语句造成的,在xml中加上:

<select id="getTeacherCounts" resultType="java.lang.Integer">
        SELECT count(*) FROM `teacherlist`
        <if test="name !=null ">
            WHERE name like #{name}
        </if>
    </select>

再运行已经成功了,前端页面能够正常显示数据:

在这里插入图片描述

2.21
出现错误码500原因之一:
xml文件中方法名的大小写与接口中的方法名大小写没对上
之后仍然再次出现错误码500
信息:
在这里插入图片描述

Cannot determine value type from string ‘数学’; nested exception is java.sql.SQLDataException: Cannot determine value type from string
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: Error attempting to get column ‘title’ from result set. Cause: java.sql.SQLDataException: Cannot determine value type from string ‘数学’
; Cannot determine value type from string ‘数学’; nested exception is java.sql.SQLDataException: Cannot determine value type from string ‘数学’] with root cause

在message实体类中加上无参构造函数之后解决。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Uncaught (in promise) Error: Request failed with status code 500 的相关文章

随机推荐

  • Postman~做接口测试

    在工作中 xff0c 接口测试势必是最有效的测试途径 因此 xff0c 学习接口测试的基础和工具是很有必要的 xff0c 从Postman开始吧 xff5e 目录 1 接口测试简介 2 接口测试流程及用例设计 3 使用Postman执行接口
  • pytest接口测试自动化框架

    目录 pytest简介及安装 pytest的使用规则 pytest运行方式 主函数方式 命令行方式 跳过 标记及预期失败特殊场景处理 pytest前后置 夹具 pytest高级用法fixture pytest接口断言 pytest结合all
  • 测试的阶段性小小总结

    转眼入职2年之余 xff0c 毕业后就投入测试行业 在日常的工作中也有自己的一些思考和总结 2021到2023是多变的两年 xff0c 加入教培行业 xff0c 受双减政策影响 xff0c 注定艰难 参与了各种类型的测试项目 xff0c 不
  • 关于Charles抓包

    目录 抓包的原理 抓包的步骤 1 下载Charles 2 PC抓HTTPS协议的包 3 移动端抓包步骤 证书的原理 抓包的原理 抓包的软件非常多 xff0c 其实底层逻辑充当了一个中间人代理的角色来对HTTPS进行抓包 xff0c 结合日常
  • Ubuntu下使用CMakeLists.txt管理C/C++代码

    Ubuntu下使用CMakeLists txt管理C C 43 43 代码 一 CMakeLists txt入门知识1 CMakeLists txt的编译方法2 CMakeLists txt的文件内容3 编译的C文件 二 CMakeList
  • C语言中的__FILE__、__LINE__和__func__等预定义宏和注意事项

    C语言预处理要求定义某些对象宏 xff0c 运用这些预定义宏能使调试变得更简单 xff0c 每个预定义宏的名称一两个下划线字符开头和结尾 xff0c 这些预定义宏不能被取消定义 xff08 undef xff09 或由编程人员重新定义 常用
  • 树莓派4B ubuntu20.04 安装ROS noetic和opencv记录

    文章目录 准备换源安装ROS一些遇到的坑连接wifi添加秘钥时出错 E could not get lock var lib apt list catkin make时出现错误 Could not find the required com
  • c语言变量和常量

    c语言的常量和变量及其类型 常量以及常量的定义 变量 xff1a 在c语言中变量就是能够改变的量 常量 xff1a 就是在定义后不能去改变的值就是常量 int a 61 10 a 61 20 此时的a就是一个变量 const int a 6
  • 头文件中只有声明,没有定义

    前言 xff1a 头文件中只有声明 xff0c 而没有定义 这是为什么呢 xff1f 刚看到这个问题我也比较纳闷 因为我学C 43 43 之前一直是这样的 xff0c 直到学习了C 43 43 中的内联函数 xff0c 内联函数的声明和定义
  • STM32-printf重定向串口输出

    声明 本文内容转载至https www mculover666 cn posts 2251182441 1 printf与fputc printf 定义在 lt stdio h gt 头文件中 xff0c 如下 xff1a span cla
  • ZYNQ7020与PC机的UDP通信实现

    由于实验室项目需求开始学习ZYNQ7000系列开发板 xff0c 了解zunq的udp通信实现 xff0c 开发板的自带学习资料有 基于UDP的QSPI Flash bin文件网络烧写实验 xff0c 该实验的基本原理如下 首先 xff0c
  • CAN 与 CANFD数据报文格式解读

    ISO 11898 1 2015 协议详细定义了CAN网络报文的格式 xff0c 包含了传统CAN与CANFD帧格式 CAN网络的帧类型共有4种 xff0c 分别为数据帧 远程帧 错误帧 过载帧 本章将主要介绍CAN网络数据帧报文的格式 x
  • #define用法详解

    1 define 的作用 在 xff23 或C 43 43 语言源程序中允许用一个标识符来表示一个字符串 xff0c 称为 宏 被定义为 宏 的标识符称为 宏名 在编译预处理时 xff0c 对程序中所有出现的 宏名 xff0c 都用宏定义中
  • *32.什么是DMA方式?什么是中断方式?有什么区别?

    DMA是l O设备与主存之间由硬件组成的直接数据通路 xff0c 主要用于高速I xff0f O设备与主存之间的成组数据传送 xff08 外设快 慢了没意义 然后数据多 xff0c 少了也没多大意义 xff09 首先讲一下外设跟内存进行数据
  • http请求报文和响应报文

    一个HTTP请求报文由四个部分组成 xff1a 请求行 请求头部 空行 请求数据 1 请求行 请求行由请求方法字段 URL字段和HTTP协议版本字段3个字段组成 xff0c 它们用空格分隔 比如 GET data info html HTT
  • stm32标准库串口的硬件控制流不用也需要配置

    usart2 USART BaudRate 61 9600 usart2 USART HardwareFlowControl 61 USART HardwareFlowControl None usart2 USART Mode 61 US
  • 解决keil总是全部编译问题

    遇到keil总是全部编译 xff0c 极大影响开发效率 xff1a 找到网上的一些修改keil工程配置 xff0c 如 use cross module optimization 一项是被选中的 xff0c 我们只需要去掉这个勾选即可 但是
  • Maven问题-访问jsp页面报错org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException

    通过maven运行含有jsp页面的项目 xff0c 只要访问jsp页面资源 xff0c 就会报错 org eclipse jdt internal compiler classfmt ClassFormatException 原因 xff1
  • 第四节---数组

    本章重点 一维数组的创建和初始化一维数组的使用一维数组在内存中的存储二维数组的创建和初始化二维数组的使用二维数组在内存中的存储数组作为函数参数 一维数组的创建和初始化 数组的创建 数组是一组相同类型元素的集合 数组的创建方式 xff1a t
  • Uncaught (in promise) Error: Request failed with status code 500

    分享一些状态码400 404 500等原因 出错 前端 span class token comment 获取所有的导航菜单 span span class token keyword async span span class token