iBatis的學習筆記

2021-10-06 21:31:21 字數 1868 閱讀 5812

官網:

環境搭建:

student.xml實體類對映檔案

別名select * from student

select sid,sname,score,major,birth from student where sid=#sid#

insert into student(sid,sname,major,score,birth)values(#sid#,#sname#,#major#,#score#,#birth#)

delete from student where sid=#sid#

update student set major=#major#,sname=#sname#,birth=#birth#,score=#score# where sid=#sid#

select sid,sname,major,birth,score from student where sname like '%$sname$%#  模糊查詢

主鍵自動生成

主鍵值自動增長

select studentpksequence.nextval as sid from dual

insert into student(sid,sname,major,score,birth)values(#sid#,#sname#,#major#,#score#,#birth#)

//定義乙個實體類

public class student

//讀取配置檔案

private static sqlmapclient sqlmapclient = null;

staticcatch(ioexception e){}

}

進行crud操作借助sqlmapclient中的方法:

定義dao層

public inte***ce istudentdao

public class istudentdaoimpl implements istudentdaocatch(){}

}public void addstudent(student student)catch(ioexception e)

}public void addstudentbysequence(student student)catch(ioexception e)

}public void deletestudentbyid(int id)catch(ioexception e)

}public void updatestudent(student student)catch(ioexception e)

}public listqueryallstudent()catch(ioexception e)

return studentlist;

}public listquerystudentbyname(string name)catch(ioexception e)

return studentlist;

}public student querystudentbyid(int id)catch(ioexception e)

return student;}}

優點:

sql語句與程式**分離,增強了移植性(與jdbc的比較)

缺點:sql語句需要手動編寫,引數parameterclass只能乙個

iBatis 2 3 4 726學習筆記

driver com.mysql.jdbc.driver url jdbc mysql localhost 3306 account 資料庫 username root 使用者名稱 password pwd 密碼 public sql map config 2.0 en public sql map...

ibatis 3 學習筆記 5

動態sql語句 可以在xml檔案中新增條件配置來動態拼接,呼叫sql語句 ibatis使用的ongl表示式有四種元素 if choose trim foreach if select id findactivebloglike parametertype blog resulttype blog s...

Ibatis學習筆記(一)簡單介紹

ibatis 是以sql 為中心的持久化層框架。能支援懶載入 關聯查詢 繼承等特性。ibatis 不同於一般的 or對映框架。or對映框架,將資料庫表 欄位等對映到類 屬性,那是一種元資料 meta data 對映。ibatis 則是將sql 查詢的引數和結果集對映到類。所以,ibatis 做的是的...