報BUG心得
報錯解決方案
iii { “timestamp”: “2018-10-28T01:06:45.391+0000”, “status”: 500, “error”: “Internal Server Error”, “message”: “nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ‘root’@‘192.168.1.100’ (using password: YES)\r\n### The error may exist in file [E:\IDEAWorkSpace\Ols\Ols_data\target\classes\mapper\mall\ApkIteratorMapper.xml]\r\n### The error may involve com.tbtx.mapper.mall.ApkIteratorMapper.selectApkLastVersion\r\n### The error occurred while executing a query\r\n### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ‘root’@‘192.168.1.100’ (using password: YES)”, “path”: “/apk/getApkLastVersion” }
這是配置資料庫密碼錯誤的緣故;
##############################
Could not get any response This seems to be like an error connecting to http://localhost:8081/apk/getApkLastVersion. Why this might have happened: The server couldn’t send a response: Ensure that the backend is working properly SSL connections are being blocked: Fix this by importing SSL certificates in Chrome Cookies not being sent: Use the Postman Interceptor extension Request timeout: Change request timeout in Settings > General
路徑中埠錯誤;
錯誤順序: 埠錯誤與頁面錯誤以及404頁面錯誤,首先會報埠錯誤,改正後才會報頁面錯誤,其次才會是500語法錯誤。
#########################
專案中的配置可以直接配置為localhost,然後在postman中可以直接進行用localhost或者直接用IP地址都是可以的。
本地執行程式碼時候,不用帶專案的全稱即可,並且可以用IP地址以及localhost都可以,還有埠可以是8080。
##########################
{ “timestamp”: “2018-10-28T02:28:33.662+0000”, “status”: 500, “error”: “Internal Server Error”, “message”: “\r\n### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘link_store.ols_course’ doesn’t exist\r\n### The error may exist in file [E:\IDEAWorkSpace\Ols\Ols_data\target\classes\mapper\ols\CourseMapper.xml]\r\n### The error may involve defaultParameterMap\r\n### The error occurred while setting parameters\r\n### SQL: SELECT courseId , courseName , coursePlatform , coursePicture ,courseMessage , courseClass , courseDetail, collectCourse ,buyNumber ,originPrice, spellPrice , spellState, courseTeacher FROM ols_course WHERE courseId = 1;\r\n### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘link_store.ols_course’ doesn’t exist\n; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘link_store.ols_course’ doesn’t exist”, “path”: “/user/getCourseComment” }
{ “timestamp”: “2018-10-28T02:25:05.529+0000”, “status”: 500, “error”: “Internal Server Error”, “message”: “\r\n### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘courseId’ in ‘field list’\r\n### The error may exist in file [E:\IDEAWorkSpace\Ols\Ols_data\target\classes\mapper\ols\CourseMapper.xml]\r\n### The error may involve defaultParameterMap\r\n### The error occurred while setting parameters\r\n### SQL: SELECT courseId , courseName , coursePlatform , coursePicture ,courseMessage , courseClass , courseDetail, collectCourse ,buyNumber ,originPrice, spellPrice , spellState, courseTeacher FROM ols_course WHERE courseId = 1;\r\n### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘courseId’ in ‘field list’\n; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column ‘courseId’ in ‘field list’”, “path”: “/user/getCourseComment” }
多資料來源需要每個資料庫基本上單獨的,可以不全配置完全,但是所需要測試介面用到的資料庫必須是存在著的,還有欄位需要對上。
###########################
{ “timestamp”: “2018-10-28T03:47:40.378+0000”, “status”: 400, “error”: “Bad Request”, “message”: “Required Integer parameter ‘id’ is not present”, “path”: “/user/getCourseComment” }
param中的值變數與xml檔案中的mybatis語句不一致
############################
上邊 2018-10-28 13:37:35,925 INFO HikariDataSource:110 - HikariPool-1 - Starting… 2018-10-28 13:37:36,255 INFO HikariDataSource:123 - HikariPool-1 - Start completed. 2018-10-28 13:37:36,265 DEBUG getCourseComment:159 - ==> Preparing: SELECT courseId , course_detail FROM ols_costcourse WHERE courseId = 1 2018-10-28 13:37:36,307 DEBUG getCourseComment:159 - > Parameters: 2018-10-28 13:37:36,343 DEBUG getCourseComment:159 - < Total: 0 下邊
標準查詢出的後臺結果
########################################
{ “orderType”: null, “extendid”: null, “msgType”: “danger”, “data”: null, “datas”: null, “totalPage”: 0, “msgDetail”: “”, “pageSize”: null, “paging”: null, “pageTo”: 10, “pageFrom”: 1, “total”: 0, “msgContent”: “”, “pageIndex”: 1, “order”: null, “status”: 1 }
{ “orderType”: null, “extendid”: null, “msgType”: “success”, “data”: { “courseId”: 1082323, “course_detail”: “課程內容系統,理論與實踐並重,強調地下工程施工技術。課程由理論教學和案例分析(48學時)、實驗教學(6學時)、課外講座(6學時)、課程設計(1周)和網路自學等五個模組構成,將地下鐵道結構構造、設計原理和施工知識有機的結合起來,引導學生視地質條件、環境條件等變化靈活應用,培養學生分析問題、解決問題的能力。” }, “datas”: null, “totalPage”: 0, “msgDetail”: “”, “pageSize”: null, “paging”: null, “pageTo”: 10, “pageFrom”: 1, “total”: 0, “msgContent”: null, “pageIndex”: 1, “order”: null, “status”: 0 }
尷尬了:竟然忘了在 service 中 返回值,所以網頁結果竟然成為了null,鬧了一波烏龍。
#########################################
ResponseUtils.createResponseDatasJsonNoPage(,) List<Map<String, Object>>
ResponseUtils.createResponseDataJsonNoPage(,) Map<String, Object> ,List<Map<String, Object>> 兩個都可以
######################################################## , { “timestamp”: “2018-10-28T07:07:26.125+0000”, “status”: 500, “error”: “Internal Server Error”, “message”: “nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘courseId’ not found. Available parameters are [id, param1]”, “path”: “/user/getCourseComment” }
傳輸的值變數有錯誤;
###################################
{ “orderType”: null, “extendid”: null, “msgType”: “success”, “data”: null, “datas”: [ { “courseName”: “we”, “courseClass”: 23, “buyNumber”: 34, “courseMessage”: “1”, “coursePicture”: “0”, “id”: 1, “originPrice”: 34, “coursePlatform”: “新東方”, “courseTeacher”: “車老師”, “collectCourse”: “天下奇聞”, “courseDetail”: “阿薩德”, “spellPrice”: 9 } ], “totalPage”: 1, “msgDetail”: “”, “pageSize”: null, “paging”: null, “pageTo”: 10, “pageFrom”: 1, “total”: 1, “msgContent”: null, “pageIndex”: 1, “order”: null, “status”: 0 }
#######################################
{ “timestamp”: “2018-10-28T08:04:59.826+0000”, “status”: 500, “error”: “Internal Server Error”, “message”: “nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ‘root’@‘192.168.1.106’ (using password: YES)\r\n### The error may exist in file [E:\IDEAWorkSpace\Ols\Ols_data\target\classes\mapper\ols\CourseMapper.xml]\r\n### The error may involve com.tbtx.mapper.ols.CourseMapper.getVideosByCourseId\r\n### The error occurred while executing a query\r\n### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Access denied for user ‘root’@‘192.168.1.106’ (using password: YES)”, “path”: “/user/selectFreeVideo” }
資料庫配置密碼錯誤
######################################
{ “timestamp”: “2018-10-29T09:39:48.401+0000”, “status”: 500, “error”: “Internal Server Error”, “message”: “nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot load connection class because of underlying exception: ‘java.lang.NumberFormatException: For input string: “:3306”’.\r\n### The error may exist in file [E:\IDEAWorkSpace\Ols\Ols_data\target\classes\mapper\member\UserMapper.xml]\r\n### The error may involve com.tbtx.mapper.member.UserMapper.selectUserByUserToken\r\n### The error occurred while executing a query\r\n### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Cannot load connection class because of underlying exception: ‘java.lang.NumberFormatException: For input string: “:3306”’.”, “path”: “/video/getEducationalByType” }
######################################
org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [E:\IDEAWorkSpace\Ols\Ols_data\target\classes\mapper\ols\CourseMapper.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.tbtx.mapper.ols.CourseMapper.selectChargeCourseByEduId
Mapper中的id 有重複
########################################
嚴重: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause java.lang.NullPointerException at com.tbtx.service.impl.CourseServiceImpl.getEduDetailByEduId(CourseServiceImpl.java:29) at com.tbtx.controller.CourseController.getEduDetailByEduId(CourseController.java:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498)
一般處理方式為: 在程式碼中判斷一下是否為空,若為空,做一下處理就OK
#######################################