一、我们在控制器层都是调用Service层,不会直接调用仓储层。现在我给大家介绍一下怎么快速实现Service 的CRUD
定义接口:IProductService 继承IService<实体>
package com.saas.plusdemo;
import com.baomidou.mybatisplus.extension.service.IService;
public interface IProductService extends IService<Product> {
}
添加实现类:ProductServiceImpl?继承ServiceImpl<Map仓储,实体>
package com.saas.plusdemo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.saas.plusdemo.mapper.IProductRepository;
import org.springframework.stereotype.Service;
@Service
public class ProductServiceImpl extends ServiceImpl<IProductRepository,Product> implements IProductService{
}
二、添加单元测试
@Test
void serviceAdd(@Autowired IProductService productService) {
Product product=new Product();
product.setId(UUID.randomUUID().toString());
product.setName("hi service");
productService.save(product);
}