| 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; | 
|     } | 
| } |