kongdeqiang
2022-09-19 a9862e81851bbe037edc6bb1c7f562c1e55c0d7f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.boying.common;
 
import com.boying.entity.WhiteList;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.Serializable;
import java.util.List;
 
public abstract class BaseService <T, ID extends Serializable>{
 
    protected BaseDao<T, ID> baseDao;
 
    protected abstract void setBaseDao(BaseDao<T, ID> baseDao);
 
    @Transactional(readOnly = false)
    public void save(T t) {
        this.baseDao.save(t);
    }
 
    @Transactional(readOnly = false)
    public void delete(ID id) {
        this.baseDao.deleteById(id);
    }
 
    public T findById(ID id) {
        return this.baseDao.getOne(id);
    }
 
    public List<T> findAll() {
        return this.baseDao.findAll();
    }
 
    public long count(Specification specification) {
        return this.baseDao.count(specification);
    }
 
    public List<T> findAll(Specification specification) {
        return this.baseDao.findAll(specification);
    }
 
 
    public Page<T> findPage(Pageable pageable) {
        Page<T> all = this.baseDao.findAll(pageable);
        return all;
    }
 
    public Page<T> findPage(Pageable pageable, Specification specification) {
        Page<T> all = this.baseDao.findAll(specification,pageable);
        return all;
    }
}