service层,抽取为接口,开启事务

抽取为接口后,

springboot事务开启,不在报错。

@Transactional
public interface DescriptionService {

    
    public Description addDescription(Description description) ;

启动类

@SpringBootApplication
@EnableTransactionManagement
@MapperScan(basePackages = {"cn.taotao.dao"})
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 20*60)
@EnableCaching
public class Zhouyi3Application {

    
    public static void main(String[] args) {
        SpringApplication.run(Zhouyi3Application.class, args);
    }

    
}

springboot的redis注解,不再报错。

@Service
public class DescriptionServiceImpl implements DescriptionService {

    @Autowired
    private DescriptionMapper descriptionMapper;
    @Autowired
    private CategoryService categoryService;
    
    //@CachePut(cacheNames = "Description",key = "#description.id")
    public Description addDescription(Description description) {
        descriptionMapper.addDescription(description);
        descriptionMapper.updateDescriptionOrder(description.getId(), description.getId()*10);
        return description;
    }
    
    @CachePut(cacheNames = "Description",key="'id:'+#description.id")
    public Description modifyDescription(Description description) {
        descriptionMapper.modifyDescription(description);
        return description;
    }

抽取接口示意图

原文地址:https://www.cnblogs.com/sdgtxuyong/p/14720689.html