一、导入通用mapper依赖``
<!--通用mapper起步依赖-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.4</version>
</dependency>
二、dao中接口集成通用mapper,注意导包属于tk下的包。
public interface BrandMapper extends Mapper<Brand> {
}
三、业务逻辑层注入mapper
@Service
public class BrandServiceImpl implements BrandService {
@Autowired
private BrandMapper brandMapper;
四、控制层注入业务逻辑层mapper
@CrossOrigin //跨域 A域名访问B域名的数据,此时存在跨域
//域名或者端口或者协议不一致,就存在跨域
public class BrandController {
@Autowired
private BrandService brandService;
五、启动类加上包扫描,注意是tk下的包。
@SpringBootApplication
@EnableEurekaClient
//注意 要使用通用的mapper的组件扫描
@MapperScan(basePackages = {"com.changgou.goods.dao"})
public class GoodsApplication {
public static void main(String[] args) {
SpringApplication.run(GoodsApplication.class, args);
}
}