基于http://www.itdecent.cn/p/b6932740f3c0來學習 Spring Boot開發(fā),出現(xiàn)的問題記錄如下:
1. 編譯錯誤
Error:(32, 24) java: 不兼容的類型: java.lang.Long無法轉換為com.yuqiyu.lessonthree.entity.UserEntity
userJPA.delete(id); 報錯,
修改為?
// userJPA.delete(id);
userJPA.deleteById(id);
2.? ?將application.yml的配置文件修改?application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.show-sql=true
spring.jpa.database=mysql
3.??Loading class `com.mysql.jdbc.Driver'. This is deprecated.
修改application.properties 中的 datasource.driver-class
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
4.? ?超時:
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
解決:
#spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8&useSSL=false
spring.datasource.url=jdbc:mysql://localhost:3306/test?characterEncoding=utf8&serverTimezone=UTC&autoReconnect=true
參考:https://www.cnblogs.com/chrischennx/p/7279215.html
5.? 輸入?http://localhost:8080/user/list, 無反饋。
java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
原因:Caused by: com.mysql.cj.exceptions.CJException: Unknown database
解決辦法: 新建 test的 數(shù)據(jù)庫文件,和對應的表格t_user

6: 執(zhí)行?http://localhost:8080/user/save?name=admin&age=22&address=jinan,?, 無反饋。
原因:
Hibernate: select next_val as id_val from hibernate_sequence for update
2019-08-29 15:16:20.993 ERROR 5284 --- [nio-8080-exec-6] o.hibernate.id.enhanced.TableStructure? : could not read a hi value
java.sql.SQLSyntaxErrorException: Table 'test.hibernate_sequence' doesn't exist
解決:
//@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
參考:
https://www.cnblogs.com/app3306/p/9176575.html
7.?執(zhí)行?http://localhost:8080/user/save?name=admin&age=22&address=jinan,?, 無反饋。
錯誤:? java.sql.SQLException: Field 't_id' doesn't have a default value
解決:在mysql數(shù)據(jù)庫中,如果自增長id沒有設為Auto Increment,在java程序中就會報java.sql.SQLException: Field 'id' doesn't have a default value錯誤。

參考: