導(dǎo)入依賴




配置連接數(shù)據(jù)庫的信息,注意h2數(shù)據(jù)庫URL的設(shè)置方式,可以直接選擇工程文件目錄

運(yùn)行main函數(shù),點(diǎn)擊登錄后顯示

系統(tǒng)會將用戶登錄信息添加到數(shù)據(jù)庫中記錄下來

遇到的最大的坑:
H2數(shù)據(jù)庫配置的時(shí)候并沒有設(shè)置用戶名和密碼,后來不知道是不是改了一下還是咋的,居然不能連接,一直就顯示用戶名和密碼錯(cuò)誤
There was an unexpected error (type=Internal Server Error, status=500).
nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password 【28000-199】 ### The error may exist in cn/edu/hnnu/community/mapper/UserMapper.java (best guess) ### The error may involve cn.edu.hnnu.community.mapper.UserMapper.insert ### The error occurred while executing an update ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.h2.jdbc.JdbcSQLInvalidAuthorizationSpecException: Wrong user name or password 【28000-199】
最后網(wǎng)上找了一個(gè)方法,用命令直接設(shè)置數(shù)據(jù)庫用戶名和密碼才解決。
CREATE USER IF NOT EXISTS 【用戶名】 PASSWORD '密碼';
ALTER USER 【用戶名】 admin true ;