日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Mybatis Example 用法手冊,接口方法和實例方法

作者:Aussise 更新時間: 2024-01-28 編程語言

一. mapper接口中的函數及方法,

方法名 功能
int countByExample(UserExample example) 按條件計數
int deleteByPrimaryKey(Integer id) 按主鍵刪除
int deleteByExample(UserExample example) 按條件查詢
String/Integer insert(User record) 插入數據(返回值為ID)
User selectByPrimaryKey(Integer id) 按主鍵查詢
ListselectByExample(UserExample example) 按條件查詢
ListselectByExampleWithBLOGs(UserExample example) 按條件查詢(包括BLOB字段)。只有當數據表中的字段類型有為二進制的才會產生。
int updateByPrimaryKey(User record) 按主鍵更新
int updateByPrimaryKeySelective(User record) 按主鍵更新值不為null的字段
int updateByExample(User record, UserExample example) 按條件更新
int updateByExampleSelective(User record, UserExample example) 按條件更新值不為null的字段

用法案例:

@Autowired //自動裝配
private MusicMapper musicMapper;

@Override
public Music queryMusicByid(Integer id) { //按主鍵查詢
    return musicMapper.selectByPrimaryKey(id);
}

二. example實例方法

example 用于添加條件,相當于where后面的部分,理論上單表的任何復雜條件查詢都可以使用example來完成。

方法 說明
example.setOrderByClause(“字段名 ASC”); 添加升序排列條件,DESC為降序
example.setDistinct(false) 去除重復,boolean型,true為選擇不重復的記錄。
example.and(Criteria criteria) 為example添加criteria查詢條件,關系為與
example.or(Criteria criteria) 為example添加criteria查詢條件,關系為或
criteria.andXxxIsNull 添加字段xxx為null的條件
criteria.andXxxIsNotNull 添加字段xxx不為null的條件
criteria.andXxxEqualTo(value) 添加xxx字段等于value條件
criteria.andXxxNotEqualTo(value) 添加xxx字段不等于value條件
criteria.andXxxGreaterThan(value) 添加xxx字段大于value條件
criteria.andXxxGreaterThanOrEqualTo(value) 添加xxx字段大于等于value條件
criteria.andXxxLessThan(value) 添加xxx字段小于value條件
criteria.andXxxLessThanOrEqualTo(value) 添加xxx字段小于等于value條件
criteria.andXxxIn(List<?>) 添加xxx字段值在List<?>條件
criteria.andXxxNotIn(List<?>) 添加xxx字段值不在List<?>條件
criteria.andXxxLike(“%”+value+”%”) 添加xxx字段值為value的模糊查詢條件
criteria.andXxxNotLike(“%”+value+”%”) 添加xxx字段值不為value的模糊查詢條件
criteria.andXxxBetween(value1,value2) 添加xxx字段值在value1和value2之間條件
criteria.andXxxNotBetween(value1,value2) 添加xxx字段值不在value1和value2之間條件

?用法案例:

@Autowired //自動裝配
private MusicMapper musicMapper;

@Override
public List<Music> queryMusicByAlbumId(Integer album_id) { //條件查詢
     MusicExample musicExample = new MusicExample();
     MusicExample.Criteria musicExampleCriteria = musicExample.createCriteria();
     musicExampleCriteria.andAlbumIdEqualTo(album_id);
     return musicMapper.selectByExample(musicExample);
}

原文鏈接:https://blog.csdn.net/qq_46509116/article/details/134045714

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新