mybatis註解開發中實體屬性和表字段不對應問題

2021-09-08 20:32:48 字數 975 閱讀 6011

在專案的實際開發中,有可能會遇到實體類中的屬性名與列名不相同,不能改但。導致不能自動裝配值的問題,此時可以接合@results、@result、@resultmap實現開發

代替的是標籤

該註解中可以使用單個@result註解,也可以使用@result集合

@results()或@results(@result())

注意:使用註解是若報出org.apache.ibatis.binding.bindingexception:invalid bound statement (not found):介面全類名.方法名

可能是使用@results註解時忘記使用@select註解

代替了 標籤和標籤

@result 中 屬性介紹:

column 資料庫的列名

property需要裝配的屬性名

one  需要使用的@one註解(@result(one=@one)()))

many  需要使用的@many註解(@result(many=@many)()))

@select("select * from course")

@results()

listqueryall();

為了解決重複使用,那就要讓他變成乙個有id的整體,其他地方要用就直接呼叫

@resultmap(「id」)

@result中通過id屬性引用這個resultmap

@select("select * from course")

@results(id = "coursemap",value = )

listqueryall();

@select("select * from coursewhere c_id=#")

@resultmap("coursemap")

course querybyid(int cid);

參考

MyBatis註解開發

mybatis作為乙個輕量級的半orm框架,由於其上手快 開發快捷,在企業中的中小型專案應用較廣泛,下面我們來演示一下如何使用mybatis的註解開發方式來進行 編寫。開發環境介紹 資料庫使用mysql,mybatis使用3.4.1 沒有使用spring整合 mysql驅動5.1.36。pojo 表...

MyBatis註解開發

insert 實現新增 update 實現更新 delete 實現刪除 select 實現查詢 result 實現結果集封裝 results 可以與 result 一起使用,封裝多個結果集 resultmap 實現引用 results 定義的封裝 one 實現一對一結果集封裝 many 實現一對多結...

MyBatis 使用註解開發

關於介面的理解 乙個個體有可能有多個抽象面。抽象體與抽象面是有區別的。三個面向區別 我們在我們的介面中新增註解 查詢全部使用者 select select id,name,pwd password from user public list getalluser 在mybatis的核心配置檔案中注入...