日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2024/9/30 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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;},

后端:

@RestController public 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 "-//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.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”:“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實體類中加上無參構造函數之后解決。

總結

以上是生活随笔為你收集整理的Uncaught (in promise) Error: Request failed with status code 500的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。