com.zyy.common.service.impl.BaseServiceImpl Maven / Gradle / Ivy
package com.zyy.common.service.impl;
import com.zyy.common.service.BaseService;
import com.zyy.common.util.BaseModel;
import com.zyy.common.util.Page;
import lombok.AllArgsConstructor;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;
@AllArgsConstructor
public abstract class BaseServiceImpl> implements BaseService {
protected final tKMapper mapper;
/**
* 通用分页查询方法
*
* @param model 插入对象
*/
@Override
public Page selectByPage(Model model) {
model.toSearchMap();
Example example = new Example(model.getClass());
example.setOrderByClause("created_on desc limit " + model.getStart() + "," + model.getPageSize());
selectCondition(example, model);
Example.Criteria criteria = example.createCriteria();
criteria.andIn("owner", model.getOwnerList());
example.and(criteria);
int countValue = mapper.selectCountByExample(example);
Page page = new Page<>(model.getCurrentPage(), countValue, model.getPageSize());
page.setList(mapper.selectByExample(example));
return page;
}
@Override
public void insert(Model model) {
mapper.insertSelective(model);
}
/**
* 通用删除方法
*
* @param id 主键
*/
@Override
public void deleteById(String id) {
mapper.deleteByPrimaryKey(id);
}
/**
* 通用修改方法
*
* @param model 修改对象
*/
@Override
public void update(Model model) {
mapper.updateByPrimaryKeySelective(model);
}
/**
* 分页查询条件方法
*
* @param example 条件
* @param model 参数对象
*/
protected void selectCondition(Example example, Model model) {
}
}