版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、JavaEE企業(yè)級框架-SSM1.JavaEE框架概Struts2MVCJavaEE企業(yè)級框架-SSM1.JavaEE框架概Struts2MVCweb 封裝Hibernate底層封裝層Spring IOC AOPspring MyBatis 層SpringSpring IOC AOPspring MyBatis 層SpringMVCwebSpring框架提供的構(gòu)建Web應(yīng)用程序的MVCSpringMVCSpring 1.2.Mybatis31.2.Mybatis3 =2.1.MybatisMyBatisapache的一個開源項目iBatis2010年這個項目由apachefoundation
2、。SQL2.1.MybatisMyBatisapache的一個開源項目iBatis2010年這個項目由apachefoundation 。SQLemen(s2.1.2.mybatis官網(wǎng)jar :MybatisSpringjar MybatisSpringjar 2.2.mybatis2.3.mybatismybatis 2.3.mybatismybatis Mybatis配置文件主要用于數(shù)據(jù)庫連接和mybatisMybatissourceMybatis配置文件主要用于數(shù)據(jù)庫連接和mybatisMybatissourcefoldersrc mybatis的DTD頭文件(在哪里找:mybatis
3、 則XML ?xml=1.0encoding=UTF-8!DOCTYPEPUBLIC-/DTDConfig !-和spring整合后environments配置-environmentsenvironment ionManager type=JDBC!- 數(shù)據(jù)庫連接池dataSourcepropertyname=driver.jdbc.Driver property:/localhost:3306/mybatis?characterEncoding=utf-8 propertyname=usernamevalue=rootpropertyname=passwordvalue=12345name
4、space id parameterType namespace id parameterType mybatismapper?xml=1.0encoding=UTF-8!DOCTYPEPUBLIC-/DTDMapper mapperselect id=selecctById parameterType= resultType=com.shop.select * from tb_user where id=#idStringconfig=mybatis-InputStreamStringconfig=mybatis-InputStream is=創(chuàng)建 Factorysf=創(chuàng)建 對象,該對象的作
5、用是調(diào)用 mapper 文件進(jìn)行數(shù)據(jù)操作(一定要先引=使用sql.selectOne(test.selecctById,關(guān)閉 對象 2.4.mybatis1)根據(jù)用戶 id 查詢,返回一個用2.4.mybatis1)根據(jù)用戶 id 查詢,返回一個用2)根模糊查詢,返回用戶列2.1)selectid=selectUserListByNameparameterType=Stringselect *from tb_userwherename public void fun1() throws IOException Stringconfig=mybatis-config.xml;InputStrea
6、minputStream =Factory sf = new SqlSes= sf.openSesUser user = sesasUserById,12); mapperselect id=selectUserById parameterType= resultType=com.shop.select * from tb_user where id= #id2.2)selectid=selectUserListByName2parameterType=2.2)selectid=selectUserListByName2parameterType=String select*fromtb_us
7、erwherenamelikepublic void fun2() throws IOException Stringconfig=mybatis-config.xml;InputStreaminputStream=Factory sf = new SqlSes= sf.openSesListuserList= for (User user : userList) 3)查詢所有用戶,select id=selectUser resultType3)查詢所有用戶,select id=selectUser resultType=com.shop.select * from tb_userpubli
8、c void fun4() throws IOException Stringconfig=mybatis-config.xml;InputStreaminputStream=public void fun3() throws IOException Stringconfig=mybatis-config.xml;InputStreaminputStream =Factory sf = new SqlSes= sf.openSesListuserList=.selectList(selectUserListByName2, for (User user : userList) 1)基publi
9、c void fun5() throws IOException Stringconfig1)基public void fun5() throws IOException Stringconfig=mybatis-config.xml;InputStreaminputStream=Factory sf = new SqlSes= sf.openSesUseruser=newUser(); .insert(insertUser,user); insert id=insertUser parameterType=com.shop.O tb_user (name,age) values (Facto
10、ry sf = new SqlSes= sf.openSesListuserList=for (User user : userList) 2)事務(wù)提 2)事務(wù)提public void fun5() throws IOException Stringconfig=mybatis-config.xml;InputStreaminputStream =Factory sf = new SqlSes= sf.openSesUseruser=newUser(); .insert(insertUser,mybatis默認(rèn)是不自動提交事id public void fun6() throws IOExce
11、ption Stringconfig=id public void fun6() throws IOException Stringconfig=mybatis-config.xml;InputStreaminputStream =insert id=insertUser2 parameterType=com.shop.UseruseGeneratedKeys=true !- SELECT LAST_INSERT_ID()-Otb_user (name,age)values insertid=insertUser2 SELECT LAST_INSERT_ID()Otb_user (name,a
12、ge)values 4)uuid 主鍵public void fun7() throws IOException String4)uuid 主鍵public void fun7() throws IOException Stringconfig=mybatis-config.xml;InputStreaminputStream =Factory sf = new SqlSes= sf.openSesinsert id=insertUser3 parameterType=com.shop.UseruseGeneratedKeys=true SELECT UUID()O tb_user (name
13、,age,uuid)values Factory sf = new SqlSes= sf.openSesUseruser=newUser(); .insert(insertUser2,user); public void fun8() throws IOException Stringpublic void fun8() throws IOException Stringconfig=mybatis-config.xml;InputStreaminputStream=Factory sf = new SqlSes = sf.openSesUser user=newUser(); User us
14、er = new User(); .insert(insertUser3,user); 3.1.myabtispublic void 3.1.myabtispublic void fun9() throws IOException Stringconfig=mybatis-config.xml;InputStreaminputStream=Factory sf = new SqlSes= sf.openSes.delete(test.deleteUser,36); ConfigStreamReader Factory 創(chuàng)建 ConfigStreamReader Factory 創(chuàng)建Factor
15、y mybatis Factory JDBCconnection3.5.mybatisUtils Factory3.5.mybatisUtils Factory使用進(jìn)4.2.mapper 4.2.1.mapper sql使用進(jìn)4.2.mapper 4.2.1.mapper sqlid4.2.2.mapper接口(重點文件編?xml=1.0encoding=UTF-8!DOCTYPEPUBLIC-/DTD Mappermapperselectid=selectUserByIdSELECT *from tb_userWHEREid= selectid=selectUser2)編寫Mapper接2)
16、編寫Mapper接packageimporterfaceUserMapperpublicUseregerSELECT*from insertid=insertUserOupdateid=updateUserUPDATEtb_userSET,age=#age,gender=#genderwhereid=delete id=deleteUser parameterType=delete from tb_user where id = #id3)Mapper 4)測3)Mapper 4)測publicvoidfun4()throwsIOExceptionmybatis配置文StringconfigX
17、ml=mybatis-InputStreaminputStream=Factory= new= sqlSesUserMapper userMapper = sesUser user = userMapper.selectUserById(35);配置文myabtis 注意:一定要注配置文myabtis 注意:一定要注意節(jié)點順序,如果順序錯了,IDE 會錯Configuration ,mybatis 5.2.1. typeAliasalias=usertypeAliasalias=producttype=cn.qn.entitytypeAliasalias=customertype=typeAliasalias=ordertype=cn.qn.entity如果是有很多個實體對象如果是有很多個實體對象,意味著仍然需要寫很多個typeA
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度總經(jīng)理職位聘請與保密協(xié)議合同
- 2025版美容機構(gòu)美容師專業(yè)聘用及培訓(xùn)合同范本3篇
- 課題申報參考:南宋私家本朝史籍修撰及其家國書寫研究
- 課題申報參考:民國時期六大疫災(zāi)的時空變遷規(guī)律、環(huán)境機理與社會影響對比研究
- 二零二五年度智慧城市規(guī)劃設(shè)計咨詢服務(wù)合同2篇
- 二零二五年度內(nèi)衣品牌授權(quán)銷售區(qū)域保護合同規(guī)范
- 2025版模板智慧農(nóng)業(yè)解決方案合同2篇
- 2025年度衛(wèi)星通信設(shè)備銷售與維護合同4篇
- 2025年度智能零售店鋪門面租賃與系統(tǒng)支持合同
- 2025年度個人買賣房屋貸款合同規(guī)范2篇
- 采購支出管理制度
- 兒科護理安全警示教育課件
- 三年級下冊口算天天100題
- 國家中英文名稱及代碼縮寫(三位)
- 人員密集場所消防安全培訓(xùn)
- 液晶高壓芯片去保護方法
- 使用AVF血液透析患者的護理查房
- 拜太歲科儀文檔
- 2021年高考山東卷化學(xué)試題(含答案解析)
- 2020新譯林版高中英語選擇性必修一重點短語歸納小結(jié)
- GB/T 19668.7-2022信息技術(shù)服務(wù)監(jiān)理第7部分:監(jiān)理工作量度量要求
評論
0/150
提交評論