spring boot整合mycat,不需要导入mycat包,只需要按照之前操作MySQL的流程去做就行,需要对SQL语句进行一些简单改造:
@Insert(“insert into table(字段) values(xxx,x,xxx)”)
①创建springboot项目 引入mysql、mybatis
```java
<dependencies>
<!-- spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<!-- mybatis -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<!-- 热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<!-- log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
``
②创建application.yml文件配置一下信息

③创建Product entity类

④编写操作数据的mapper

⑤编写service

⑥实现类

⑦编写handler

⑧编写启动类

本文详细介绍了如何在SpringBoot项目中整合Mycat,包括项目搭建、依赖引入、配置编写、实体类创建、Mapper编写、Service实现、Handler编写及启动类设置。通过实例演示了SQL语句改造及常见问题解决。
521

被折叠的 条评论
为什么被折叠?



