天天看點

springboot整合mybatis出現list長度大于0,但是All elements are null

問題:

這兩天在使用springboot整合mybatis的時候出現的很迷惑的問題,前台頁面取不到資料,調試controller層時發現,當傳回一個對象時,該對象為空,當傳回一個list時,list的長度不為0,打開顯示發現,内部所有的對象都為空

springboot整合mybatis出現list長度大于0,但是All elements are null

解決方案:

根據查閱網上的資料,發現原來是需要打開“MyBatis配置檔案開啟駝峰命名映射”,隻有這樣,才能映射到字段,進而建立出不為空的對象,接下來大家隻要開啟這個就可以了,開啟的方式為:

如果是在mybatis-config.xml中開啟,需要在配置檔案中的settings中加入

springboot整合mybatis出現list長度大于0,但是All elements are null

如果是在application.properties中配置的話,需要加入:mybatis.configuration.map-underscore-to-camel-case=true,不過建議大家在mybatis-config.xml中加入該設定

出現新的錯誤?

如果大家在application.properties中配置的話,可能會出現Property 'configuration' and 'configLocation' can not specified with together的錯誤提示,這個原因是因為configuration 和 configLocation 不能同時存在,是以需要在application.properties把該配置注釋掉,到mybatis-config.xml中開啟該配置

springboot整合mybatis出現list長度大于0,但是All elements are null