模仿bilibili做了一個pilipili在線視頻網站
源碼已全部托管至github:https://github.com/BrucessKING/pilipili
我主要負責接口的實現
leader給了我兩個接口:UserDao VideoDao
使用的框架為SSM
今天遇到的錯誤問題:
1 org.apache.ibatis.exceptions.PersistenceException: 2 ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, releaseDate, clickTimes, pictureUrls, videoUrl, state, user_id, category_i' at line 1 3 ### The error may involve defaultParameterMap 4 ### The error occurred while setting parameters 5 ### SQL: insert into p_video(name, desc, releaseDate, clickTimes, pictureUrls, videoUrl, state, user_id, category_id) values(?, ?, ?, ?, ?, ?, ?, ?, ?) 6 ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc, releaseDate, clickTimes, pictureUrls, videoUrl, state, user_id, category_i' at line 1
明明沒有語法錯誤,可是仍然報錯。。。
后來發現,在建表時,居然使用了desc關鍵字作為列名
解決的方法為:使用反單引號把desc引起來
sql語句如下:
1 insert into p_video(`name`, `desc`, releaseDate, clickTimes, pictureUrls, videoUrl, state, user_id, category_id) values(#{video.name}, #{video.desc}, #{video.releaseDate}, #{video.clickTimes}, #{video.pictureUrls}, #{video.videoUrl}, #{video.state}, #{user_id}, #{category_id})
2019-12-26 15:30
報錯如下:
1 org.apache.ibatis.exceptions.PersistenceException: 2 ### Error querying database. Cause: java.lang.UnsupportedOperationException 3 ### The error may exist in file [D:\Git_Repository\pilipili\target\classes\mapper\VideoDao.xml] 4 ### The error may involve com.pilipili.dao.VideoDao.selectVideosByClickTimes 5 ### The error occurred while handling results 6 ### SQL: select id, `name`, `desc`, releaseDate, clickTimes, pictureUrls, videoUrl, state, user_id, category_id from p_video where user_id=? order by clickTimes desc limit 0, ? 7 ### Cause: java.lang.UnsupportedOperationException
原因是在 VideoDao.xml 中 resultType="list"
即使要返回list類型,這里也應該寫成video類型,如果查詢到多條數據,會自動放入list中