說明一下,關於ssm框架,以前我沒有深刻接觸過,直到最近由於項目須要,才作了一些研究,如有錯誤,還麻煩各位大佬能及時指出!app
首先mapper接口中的函數及方法框架
按條件查詢個數函數
long countByExample(CandidateExample example);接口
根據條件刪除it
int deleteByExample(CandidateExample example);配置
根據主鍵刪除date
int deleteByPrimaryKey(Integer id);List
整條插入select
int insert(Candidate record);map
有選擇性插入
int insertSelective(Candidate record);
按條件查詢表,返回一個集合
ListselectByExample(CandidateExample example);
按主鍵查詢,返回一個個體
Candidate selectByPrimaryKey(Integer id);
按條件有選擇的進行更新
int updateByExampleSelective(@Param(record) Candidate record,
@Param(example) CandidateExample example);
按條件進行更新
int updateByExample(@Param(record) Candidate record,
@Param(example) CandidateExample example);
按主鍵有選擇的進行更新
int updateByPrimaryKeySelective(Candidate record);
按主鍵更新
int updateByPrimaryKey(Candidate record);
對每個方法進行具體查詢
整條插入
candidateMapper.insert(new Candidate(根據有參構造器裏的參數進行具體傳值));
有選擇性插入
candidateMapper.insertSelective(new Candidate());//根據具體類對應的配置文件進行傳值
根據主鍵刪除
candidateMapper.deleteByPrimaryKey(1);
按主鍵查詢,返回一個個體
candidateMapper.selectByPrimaryKey(2);
按主鍵更新
candidateMapper.updateByPrimaryKey(new Candidate());//注意配置文件的相應規則
按主鍵有選擇的進行更新
candidateMapper.updateByPrimaryKeySelective();
如下是重點
按條件查詢個數
CandidateExample example = new CandidateExample();
CandidateExample.Criteria criteria = example.createCriteria();
long count = candidateMapper.countByExample(example);
System.out.println(count);
根據條件刪除
criteria.andDstateGreaterThan(20);
candidateMapper.deleteByExample(example);
注意下面的這一步必需要給對應的類構造無參方法
按條件查詢表,返回一個集合
example.setOrderByClause(did asc);//升降序
example.setDistinct(false);//是否去重複
criteria.andDstateEqualTo(3);
ListcandidateList=candidateMapper.selectByExample(example);
for(Candidate list:candidateList){
System.out.println(list.toString());
}
按條件進行更新
criteria.andDstateGreaterThan(10);
candidateMapper.updateByExample(new Candidate(record),example);
按條件有選擇的進行更新
criteria.andDidGreaterThan(90);
candidateMapper.updateByExampleSelective(new Candidate(record),example ) ;