cjl
2023-10-13 100690a225167806a08f64eafff3326564a7154a
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.moral.api.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.entity.Test;
import com.moral.api.exception.BusinessException;
import com.moral.api.mapper.TestMapper;
import com.moral.api.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.Map;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-02-25
 */
@Service
@ConfigurationProperties(prefix = "code")
public class TestServiceImpl extends ServiceImpl<TestMapper, Test> implements TestService {
 
    @Resource
    private TestMapper testMapper;
 
    Map<String,String> map;
 
    public void setMap(Map<String, String> map) {
        this.map = map;
    }
 
    @Override
    public Page<Test> selectByPage(Test test, Integer page, Integer size) {
        //设置分页条件
        Page<Test> pageData = new Page<>(page, size);
        //执行分页查询
        IPage<Test> users = testMapper.selectPage(pageData, new QueryWrapper<>(test));
        //设置结果集到分页对象中
        pageData.setRecords(users.getRecords());
        //返回结果
        return pageData;
    }
 
    @Override
    @Transactional
    public void saveTest() throws Exception{
        Test t=new Test();
        t.setName("aaaa");
        t.setMobile("139652555");
        t.setEmail("33@qq.com");
        testMapper.insert(t);
        if ("aaaa".equals(t.getName())){
            throw new BusinessException("aaaa已存在,数据将不会回滚");
        }
 
    }
 
    @Override
    public Map<String,String> getMap(){
        return map;
    }
}