说明一下,关于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 ) ;