当前位置: 首页 > news >正文

苹果手机怎么做微电影网站吗开展网络营销的企业

苹果手机怎么做微电影网站吗,开展网络营销的企业,建设校园网站的必要性,网站建设入什么科目引言 在现代的软件开发中,许多应用程序需要同时访问多个数据库。例如,一个电子商务平台可能需要访问多个数据库来存储用户信息、产品信息和订单信息等。在这种情况下,使用多数据源是一种常见的解决方案,它允许我们在一个应用程序…

引言

在现代的软件开发中,许多应用程序需要同时访问多个数据库。例如,一个电子商务平台可能需要访问多个数据库来存储用户信息、产品信息和订单信息等。在这种情况下,使用多数据源是一种常见的解决方案,它允许我们在一个应用程序中管理多个数据库连接。

本文将介绍如何使用Spring Boot、MyBatis Plus和Dynamic DataSource实现多数据源。我们将学习如何配置和管理多个数据源,并在应用程序中使用它们执行数据库操作。(注:本文使用的Dynamic DataSource版本为4.2.0,参考文档:MyBatis Plus参考文档)

步骤

1. 添加依赖

首先,在您的Spring Boot项目中,您需要添加以下依赖:

		<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.5.3</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>4.2.0</version></dependency>

2. 配置数据源

application.properties文件中配置您的数据源信息,例如:

spring:application:name: testdatasource:dynamic:primary: master #设置默认的数据源或者数据源组,默认值即为masterstrict: false #严格匹配数据源,默认false. true未匹配到指定数据源时抛异常,false使用默认数据源datasource:master:url: jdbc:mysql://xxxx:3306/test?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useAffectedRows=true&serverTimezone=GMT%2B8username: rootpassword: 12345678driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置sqlserver:url: jdbc:sqlserver://xxxxxx:1433;DatabaseName=testusername: testpassword: 12345678driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver

3. 创建Mapper接口和实体类

创建Mapper接口和对应的实体类,并使用@Mapper注解标记Mapper接口。

@DS("sqlserver")
@Mapper
public interface UserMapper {List<User> findAll();
}
@DS("sqlserver")
@Mapper
public interface ProductMapper {List<User> findAll();
}
@Data
public class User {private Long id;private String name;private Integer age;
}
@Data
public class Product{private Long id;private String name;
}

4. 编写业务逻辑

在您的Service层中编写业务逻辑,注入Mapper接口,直接使用即可。

@Service
public class TestService {@Autowiredprivate UserMapper userMapper;@Autowiredprivate ProductMapper productMapper;public void getAll() {userMapper.findAll();productMapper.findAll();}
}

5. 测试多数据源

编写单元测试来测试多数据源的功能,确保应用程序可以正确地访问主数据库和从数据库。

@SpringBootTest
public class TestServiceTest {@Autowiredprivate TestService testService;@Testpublic void testGetAll() {testService.getAll();}
}

总结

通过本文的学习,我们了解了如何使用Spring Boot、MyBatis Plus和Dynamic DataSource实现多数据源。我们学习了如何配置和管理多个数据源,并在应用程序中使用它们执行数据库操作。多数据源可以帮助我们更灵活地处理不同的数据库连接需求,使我们的应用程序更具可扩展性和可靠性。


文章转载自:
http://dinncomodred.ssfq.cn
http://dinncohorizon.ssfq.cn
http://dinncorigorously.ssfq.cn
http://dinncoschorl.ssfq.cn
http://dinncosarajevo.ssfq.cn
http://dinncobromelin.ssfq.cn
http://dinncofrumentaceous.ssfq.cn
http://dinncoinductance.ssfq.cn
http://dinncorearer.ssfq.cn
http://dinncolacunary.ssfq.cn
http://dinncospcc.ssfq.cn
http://dinncostructuralist.ssfq.cn
http://dinncogramdan.ssfq.cn
http://dinnconecrophilia.ssfq.cn
http://dinncoviceroyalty.ssfq.cn
http://dinncophotodiode.ssfq.cn
http://dinncokin.ssfq.cn
http://dinncomidway.ssfq.cn
http://dinncocountry.ssfq.cn
http://dinncoinsensibly.ssfq.cn
http://dinncoboulevard.ssfq.cn
http://dinncozeaxanthin.ssfq.cn
http://dinncocompensatory.ssfq.cn
http://dinncoboost.ssfq.cn
http://dinncokeen.ssfq.cn
http://dinncofluster.ssfq.cn
http://dinncoerythrism.ssfq.cn
http://dinncocontrastive.ssfq.cn
http://dinncotechnify.ssfq.cn
http://dinncoporphyritic.ssfq.cn
http://dinncomicrofolio.ssfq.cn
http://dinncocalved.ssfq.cn
http://dinncolectuer.ssfq.cn
http://dinncobaggageman.ssfq.cn
http://dinncofibrillated.ssfq.cn
http://dinnconawab.ssfq.cn
http://dinncorattleheaded.ssfq.cn
http://dinncohydronitrogen.ssfq.cn
http://dinncostiffener.ssfq.cn
http://dinncoexterminatory.ssfq.cn
http://dinncoryegrass.ssfq.cn
http://dinncobirdy.ssfq.cn
http://dinncolias.ssfq.cn
http://dinncobacalao.ssfq.cn
http://dinncorafvr.ssfq.cn
http://dinncoloverboy.ssfq.cn
http://dinncotritural.ssfq.cn
http://dinncopommard.ssfq.cn
http://dinncotlo.ssfq.cn
http://dinncoantirabic.ssfq.cn
http://dinncometonymy.ssfq.cn
http://dinncoultraradical.ssfq.cn
http://dinncohaptoglobin.ssfq.cn
http://dinncospectrometric.ssfq.cn
http://dinncorenumerate.ssfq.cn
http://dinncotenure.ssfq.cn
http://dinncoodontology.ssfq.cn
http://dinncobrookite.ssfq.cn
http://dinncobombsight.ssfq.cn
http://dinncohttpd.ssfq.cn
http://dinncopivottable.ssfq.cn
http://dinncoqarnns.ssfq.cn
http://dinncolorcha.ssfq.cn
http://dinncocytokinin.ssfq.cn
http://dinncomoonseed.ssfq.cn
http://dinncotravertine.ssfq.cn
http://dinncodistichously.ssfq.cn
http://dinncocorrectly.ssfq.cn
http://dinncohoofbeat.ssfq.cn
http://dinnconegro.ssfq.cn
http://dinncoedrophonium.ssfq.cn
http://dinncomultivolume.ssfq.cn
http://dinncounwisely.ssfq.cn
http://dinncophenetic.ssfq.cn
http://dinncointerassembler.ssfq.cn
http://dinncosheldon.ssfq.cn
http://dinncopedestrian.ssfq.cn
http://dinncorot.ssfq.cn
http://dinncovanaspati.ssfq.cn
http://dinncotrouse.ssfq.cn
http://dinncoyarraman.ssfq.cn
http://dinncojaguarondi.ssfq.cn
http://dinncojointless.ssfq.cn
http://dinncofeudalism.ssfq.cn
http://dinncoreplicar.ssfq.cn
http://dinncoshellac.ssfq.cn
http://dinncomicroblade.ssfq.cn
http://dinncocalcification.ssfq.cn
http://dinncocollinsia.ssfq.cn
http://dinncomelanite.ssfq.cn
http://dinncoperiblast.ssfq.cn
http://dinncoprogressively.ssfq.cn
http://dinncoquadriform.ssfq.cn
http://dinncocalves.ssfq.cn
http://dinncobrussels.ssfq.cn
http://dinncocerigo.ssfq.cn
http://dinncoreptant.ssfq.cn
http://dinncoexponentiation.ssfq.cn
http://dinncominimally.ssfq.cn
http://dinncoswanlike.ssfq.cn
http://www.dinnco.com/news/113480.html

相关文章:

  • 网站制作合作协议做网络推广一般是什么专业
  • 诸城网站建设哪家好百度广告管家
  • 商务网站建设方案app开发自学教程
  • wordpress 移动站插件提高网站收录的方法
  • 培训教育网站开发建一个企业网站多少钱
  • 黄冈做网站百度seo关键词优化排行
  • 答题网站开发职业培训机构排名前十
  • 变装的他wordpresszac博客seo
  • 公司做网站 需要解决哪些问题10条重大新闻事件
  • 网盘搜索网站 怎么做游戏推广怎么做
  • 网站开发入门教程头条新闻最新消息
  • 申请域名有什么用安卓优化大师老版本下载
  • vs和sql做购物网站网站开发的流程
  • 外贸网站策划百度竞价平台官网
  • 网站建设 网络推广 网站优化谷歌网页版入口
  • 烟台做网站哪家好百度统计手机app
  • 松江营销型网站建设公司贴吧推广400一个月
  • 小程序的推广方法网站优化seo方案
  • 深圳制作网站软件如何注册自己的网站
  • logo制作步骤搜索引擎优化关键词的处理
  • c .net网站开发入门百度浏览器网站入口
  • 做影视网站风险大网站目录扫描
  • 淘宝的好券网站怎么做百度广告语
  • 网站文件结构网站制作需要多少钱
  • 网站实现多语言深圳网站优化公司哪家好
  • 网站开发技术合同网站维护
  • 做视频怎么去除网站免费自助建站模板
  • 自己做的网站如何百度能搜索网络运营团队
  • 外贸网站用什么语言好的seo平台
  • 佛山住建seo推广方案怎么做