Mybatis mapper接口動態(tài)代理開發(fā)步驟解析
一、必須遵守的四項原則
1:接口 方法名==xx.xml中的id名
2:方法返回值類型與Mapper.xml文件中返回值類型一致
3:方法的入?yún)㈩愋团cMapper.xml文件中入?yún)⒅殿愋鸵恢?/p>
4:命名空間綁定接口
二、代碼
public class UserMapperTest {private SqlSession sqlSession;private InputStream in;@Beforepublic void before() throws IOException { //1.讀取配置文件 in = Resources.getResourceAsStream('SqlMapConfig.xml'); //2.創(chuàng)建 SqlSessionFactory 的構(gòu)建者對象 SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); //3.使用構(gòu)建者創(chuàng)建工廠對象 SqlSessionFactory SqlSessionFactory sqlSessionFactory = builder.build(in); sqlSession = sqlSessionFactory.openSession();}@Afterpublic void after() throws IOException { //7.釋放資源 sqlSession.close(); in.close();}@Testpublic void findUserById() { UserMapper userMapper = sqlSession.getMapper(UserMapper.class); List<User> users = userMapper.findAll(); for (User user : users) { System.out.println(user); }}}
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 關(guān)于MySQL的ORDER BY排序詳解2. 詳解sql server中數(shù)據(jù)庫快照工作原理3. sql server的cube操作符使用詳解4. Mysql入門系列:安排預防性的維護MYSQL數(shù)據(jù)庫服務(wù)器5. MySQL 參數(shù)相關(guān)概念及查詢更改方法6. Mybatis 一級緩存與二級緩存的實現(xiàn)7. 我的oracle筆記六(oracle優(yōu)化方面)8. sql server 2000無法打開1433端口9. SQL Server數(shù)據(jù)庫超級管理員賬號防護知識10. 為SQLite3提供一個ANSI到UTF8的互轉(zhuǎn)函數(shù)
