mybatis取數據庫爲null的字段

數據庫中存在int型的字段,但是初始值爲null,mybatis取值之後就會報錯,

org.apache.ibatis.binding.BindingException: Mapper method 'getSort' <br>      (xx.yy.cc.DxxDAO) attempted to return null from a method with a primitive return type (int).

解決:採用了取巧的方式,將實體類對應的該字段設置成String類型,mybatis取出來之後自動轉換成string,不會報錯,業務邏輯上得自己判斷取出來的值爲null的實際用處。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章