mybatis中的mapper介面檔案以及example類的執行個體函數以及詳解

來源:互聯網
上載者:User

標籤:函數   java   gre   record   pre   .com   一個   use   rom   

##Example example = new ##Example();    example.setOrderByClause("欄位名 ASC"); //升序排列,desc為降序排列。    example.setDistinct(false)//去除重複,boolean型,true為選擇不重複的記錄。    Criteria criteria = new Example().createCriteria();    is null;is not null;    equal to(value);not equal to(value);    GreaterThan(value);GreaterThanOrEqualTo(value);    LessThan(value); LessThanOrEqualTo(value);    in(item,item,item,...);not in(item,item,item,...);    like("%"+value+"%");not like("%"+value+"%");    Between(value1,value2);not between(value1,value2)        mybatis中mapper的執行個體函數:    int countByExample(UserExample example) thorws SQLException:按條件計數。    int deleteByPrimaryKey(Integer id) thorws SQLException:按主鍵刪除。    int deleteByExample(UserExample example) thorws SQLException:按條件刪除。    String/Integer insert(User record) thorws SQLException:插入(傳回值為id值)    User selectByPrimaryKey(Integer id) thorws SQLException:按主鍵查詢。    List<?>selectByExample(UserExample example) thorws SQLException:按條件查詢    List<?>selectByExampleWithBLOGs(UserExample example) thorws SQLException:按        條件查詢(包括BLOB欄位)。只有當資料表中的欄位類型有為二進位的才會產生。    int updateByPrimaryKey(User record) thorws SQLException:按主鍵更新    int updateByPrimaryKeySelective(User record) thorws SQLException:按主鍵更新         值不為null的欄位    int updateByExample(User record, UserExample example) thorws SQLException:     按條件更新    int updateByExampleSelective(User record, UserExample example) thorws          SQLException:按條件更新值不為null的欄位        mybatis中mapper的執行個體函數詳解:    ① selectByPrimaryKey()        User user = ##Mapper.selectByPrimaryKey(100); 相當於select * from user where      id = 100        ② selectByExample() 和 selectByExampleWithBLOGs()        UserExample example = new UserExample();    Criteria criteria = example.createCriteria();    criteria.andUsernameEqualTo("joe");    criteria.andUsernameIsNull();    example.setOrderByClause("username asc,email desc");    List<?>list = ##Mapper.selectByExample(example);    相當於:select * from user where username = ‘joe‘ and username is null order        by username asc,email desc        註:在iBator 產生的檔案UserExample.java中包含一個static 的內部類 Criteria ,       在Criteria中有很多方法,主要是定義SQL 陳述式where後的查詢條件。        ③ insert()       User user = new User();    user.setId(101);    user.setUsername("test");    user.setPassword("123")    user.setEmail("[email protected]");    ##Mapper.insert(user);    相當於:insert into user(ID,username,password,email) values        (101,‘test‘,‘123‘,‘[email protected]‘);         ④ updateByPrimaryKey() 和 updateByPrimaryKeySelective()        User user =new User();    user.setId(101);    user.setUsername("joe");    user.setPassword("joe");    user.setEmail("[email protected]");    ##Mapper.updateByPrimaryKey(user);    相當於:update user set username=‘joe‘,password=‘joe‘,email=‘[email protected]‘        where id=101       User user = new User();    user.setId(101);    user.setPassword("joe");    ##Mapper.updateByPrimaryKeySelective(user);    相當於:update user set password=‘joe‘ where id=101        ⑤ updateByExample() 和 updateByExampleSelective()        UserExample example = new UserExample();    Criteria criteria = example.createCriteria();    criteria.andUsernameEqualTo("joe");    User user = new User();    user.setPassword("123");    ##Mapper.updateByPrimaryKeySelective(user,example);    相當於:update user set password=‘123‘ where username=‘joe‘       ⑥ deleteByPrimaryKey()       ##Mapper.deleteByPrimaryKey(101);  相當於:delete from user where id=101       ⑦ deleteByExample()       UserExample example = new UserExample();    Criteria criteria = example.createCriteria();    criteria.andUsernameEqualTo("joe");    ##Mapper.deleteByExample(example);    相當於:delete from user where username=‘joe‘        ⑧ countByExample()        UserExample example = new UserExample();    Criteria criteria = example.createCriteria();    criteria.andUsernameEqualTo("joe");    int count = ##Mapper.countByExample(example);    相當於:select count(*) from user where username=‘joe‘

 

mybatis中的mapper介面檔案以及example類的執行個體函數以及詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.