第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > Uncaught (in promise) Error: Request failed with status code 500

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

时间:2022-02-26 19:18:40

相关推荐

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

分享一些状态码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;},

后端:

@RestControllerpublic class MenuController {@AutowiredMenuDao 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 "-////DTD Mapper 3.0//EN""/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.Driverurl: jdbc:mysql://localhost:3308/data1?useSSL=false&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTCusername: heziyipassword: 123456

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

错误码404:

发现是因为controller类上面没有加@RestController注解

2.17日又一次出现错误码500

response报错:

{“timestamp”:“-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 stringServlet.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实体类中加上无参构造函数之后解决。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。