Spring Boot如何详细实现与数据库的关联模块创建?

2026-05-16 03:581阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计423个文字,预计阅读时间需要2分钟。

Spring Boot如何详细实现与数据库的关联模块创建?

创建步骤:

1.引入依赖

2.配置文件

3.创建启动类

依赖引入:

xml org.springframework.cloud spring-cloud-starter-openfeign provided

创建步骤

1.导入依赖

2.配置文件

3.创建启动类

Spring Boot如何详细实现与数据库的关联模块创建?

1.导入依赖

<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <!--自定义公共模块,可见公共模块文章--> <dependency> <groupId>com.xx</groupId> <artifactId>common_db</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.xx</groupId> <artifactId>service_goods_api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>

2.配置文件

server: port: 9011 spring: application: name: goods datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://192.168.200.128:3306/goods?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC username: root password: root eureka: client: service-url: defaultZone: 127.0.0.1:6868/eureka instance: prefer-ip-address: true feign: hystrix: enabled: true #hystrix 配置 hystrix: command: default: execution: timeout: #如果enabled设置为false,则请求超时交给ribbon控制 enabled: true isolation: strategy: SEMAPHORE

3.创建启动类

@SpringBootApplication @EnableEurekaClient //@MapperScan是tk.mybatis.spring.annotation包下的,用于扫描Mapper接口* @MapperScan(basePackages = {"com.goods.dao"}) public class GoodsApplication { public static void main(String[] args) { SpringApplication.run(GoodsApplication.class); } }

总结

到此这篇关于spring boot创建和数据库关联模块的文章就介绍到这了,更多相关springboot创建数据库关联模块内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

本文共计423个文字,预计阅读时间需要2分钟。

Spring Boot如何详细实现与数据库的关联模块创建?

创建步骤:

1.引入依赖

2.配置文件

3.创建启动类

依赖引入:

xml org.springframework.cloud spring-cloud-starter-openfeign provided

创建步骤

1.导入依赖

2.配置文件

3.创建启动类

Spring Boot如何详细实现与数据库的关联模块创建?

1.导入依赖

<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <!--自定义公共模块,可见公共模块文章--> <dependency> <groupId>com.xx</groupId> <artifactId>common_db</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.xx</groupId> <artifactId>service_goods_api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>

2.配置文件

server: port: 9011 spring: application: name: goods datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://192.168.200.128:3306/goods?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC username: root password: root eureka: client: service-url: defaultZone: 127.0.0.1:6868/eureka instance: prefer-ip-address: true feign: hystrix: enabled: true #hystrix 配置 hystrix: command: default: execution: timeout: #如果enabled设置为false,则请求超时交给ribbon控制 enabled: true isolation: strategy: SEMAPHORE

3.创建启动类

@SpringBootApplication @EnableEurekaClient //@MapperScan是tk.mybatis.spring.annotation包下的,用于扫描Mapper接口* @MapperScan(basePackages = {"com.goods.dao"}) public class GoodsApplication { public static void main(String[] args) { SpringApplication.run(GoodsApplication.class); } }

总结

到此这篇关于spring boot创建和数据库关联模块的文章就介绍到这了,更多相关springboot创建数据库关联模块内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!