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

网站建设开发费用预算长沙百度百科

网站建设开发费用预算,长沙百度百科,学习网站开发教程,wordpress板娘插件本文会以 mybatis 为例,通过对比 mybatis-spring 和 mybatis-spring-boot-starter 代码示例,了解 Starter 的作用。并对 mybatis-spring-boot-starter 进行简单剖析,了解 Starter 原理。 下面还有投票,一起参与进来吧&#x1f44d…

本文会以 mybatis 为例,通过对比 mybatis-spring 和 mybatis-spring-boot-starter 代码示例,了解 Starter 的作用。并对 mybatis-spring-boot-starter 进行简单剖析,了解 Starter 原理。
下面还有投票,一起参与进来吧👍

文章目录

  • 前言
  • 什么是 Starter
  • Starter 的作用
    • spring 整合组件
    • spring-boot 整合组件
  • Starter 原理

前言

有没有在入行后直接基于 SpringBoot 开发项目,没有 spring、servlet 开发经历的,举个手😄。

有没有用 SpringBoot 开发项目,但是第一次听说 Starter 或者听过却不知道是干嘛的,举个手😄。

有没有知道 Starter 是干嘛的,但不知其原理的,举个手😄。

有没有想了解 Starter 原理或想自己实现一个 Starter 提供别人使用的,举个手😄。

如果有以上情况的,希望通过本文可以帮助你了解 Starter 。

什么是 Starter

大家都知道基于 SpringBoot 开发项目可以简化 Spring 应用的搭建以及开发过程,提高程序员开发效率,这是由于其“约定大约配置”的策略及其自动装配的特点。

约定大约配置是指 SpringBoot 指定了特定的方式进行配置(application.properties/yam/yaml),开发人员不需要像在 Spring 框架开发时定义配置文件。

自动装配是指在使用某个组件或框架时需要引用其依赖、配置类、配置文件等工作时,SpringBoot 帮我们做了这些工作。

那跟 Starter 有关系吗?答案是:有! Starter 就是自动装配的具体实现,其就是一个 maven 项目,对某个组件的依赖、配置进行管理。通过导入 “Starter” 模块更容易使用这个组件。

Starter 的作用

我们通过对比 mybatis-springmybatis-spring-boot-starter 代码示例,了解 Starter 的作用。

spring 整合组件

先看下在 spring 项目中如何使用 mybatis 的。大概有以下几个步骤:

  1. 引入 spring、mybatis、jdbc 等相关依赖。
  2. 创建 mybatis-config.xml 配置文件。
    • 声明数据源 DataSource。
    • 声明 SqlSessionFactoryBean。
    • 声明 MapperScannerConfigurer。
    • 声明等等配置。
  3. 编写 xxxMapper.xmlxxMapper.java 文件。
  4. 业务编码调用。

相关依赖

<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.5.RELEASE</version>
</dependency>
<dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.1</version>
</dependency>
<dependency><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>1.3.0</version>
</dependency>
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.9</version>
</dependency>
<dependency><groupId>xxx</groupId><artifactId>xxxx</artifactId><version>xxx</version>
</dependency>
...

mybatis-config.xml 配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><context:property-placeholder location="classpath:jdbc.properties"/><settings><setting name="logImpl" value="STDOUT_LOGGING"/></settings><mappers><package name="com.xxx.dao"/></mappers><bean id="myDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close"><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="mapperLocations" value="classpath:xxxx/*.xml"/></bean><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"><property name="basePackage" value="com.xxx.dao"/></bean><bean class=".xxxxxx.xxx"><!-- 指定SqlSessionFactory对象的名称 --><property name="sqlSessionFactoryBeanName" value="factory"/><!-- 指定基本包,dao接口所在的包名 --><property name="basePackage" value="com.xxx.dao"/></bean><bean class=".xxxxxx.xxx">...</bean></configuration>

业务编码调用

@Autowired
private XxxDao xxxDao;xxxDao.insert(xx);

作为一个开发人员是否觉得很麻烦?答案一定是的,如果稍不留神少了哪个配置或依赖,那就排查问题吧😄。

spring-boot 整合组件

这时候我们如果用基于 SpringBoot 开发,那 mybatis-spring-boot-starter 就可以帮助我们做这些事。

那我们继续看下在 SpringBoot 项目中如何使用 Mybatis 的。大概有以下几个步骤:

  1. 引入 mybatis-spring-boot-starter 依赖。
  2. application.properties 文件中添加相关配置。
  3. 编写 xxxMapper.xmlxxMapper.java 文件。
  4. 业务编码调用。

引入 mybatis-spring-boot-starter 依赖

<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.1</version>
</dependency>

application.properties 文件中添加相关配置。

 spring.datasource.username=x********spring.datasource.password=********spring.datasource.url=********spring.datasource.driver-class-name=********​mybatis.mapper-locations=classpath:mapper/*.xml

编写 xxxMapper.xmlxxMapper.java 文件

@Mapperpublic interface XXXMapper {List<XXX> list(xxx);}

业务编码调用

@Autowired
private XxxDao xxxDao;xxxDao.insert(xx);

通过以上的代码比较可以明显的感觉到利用 Starter 后,我们编写的代码更少了,特别是 1、2 步骤,这就是 Starter 的作用mybatis-spring-boot-starter 帮助我们做了以下几件事:

  1. 整合了组件相关的依赖,使我们直接引入 mybatis-spring-boot-starter 依赖即可,也避免了版本冲突问题。
  2. 自动发现存在的 DataSource,做到自动配置。
  3. 帮我们创建并注册SqlSessionFactory、SqlSessionTemplate等,减少了配置类、配置项。
  4. 自动扫描映射器(Mapper),注入到 Spring Bean 中。

Starter 原理

mybatis-spring-boot-starter 是如何做这些事的,我们扒开裤子看个究竟😄。

首先看 mybatis-spring-boot-starter 项目结构,其只有一个pom.xml文件,文件中已经帮我们引入相关依赖,跟上面 Spring 整合 Mybatis 的依赖是不是差不多。

在这里插入图片描述

其中有一个 mybatis-spring-boot-autoconfigure 依赖,我们看下其项目结构

在这里插入图片描述

其通过 SPI 机制引入了 MybatisAutoConfiguration 配置类,该类帮我们做了以下几件事:

  1. 发现存在的 DataSource 并注入配置。在这里插入图片描述

  2. 注册 SqlSessionFactorySqlSessionTemplate 到 Spring 容器中。在这里插入图片描述

  3. 内部类 AutoConfiguredMapperScannerRegistrar 扫描存在 @Mapper 注解类转化为 BeanDefinition 并注册到 Spring 容器中。在这里插入图片描述


文章转载自:
http://sheerhulk.bfmq.cn
http://swivelpin.bfmq.cn
http://bikeway.bfmq.cn
http://giddyhead.bfmq.cn
http://kuibyshev.bfmq.cn
http://thieve.bfmq.cn
http://aweto.bfmq.cn
http://stratopause.bfmq.cn
http://baptismally.bfmq.cn
http://planes.bfmq.cn
http://samink.bfmq.cn
http://reroute.bfmq.cn
http://website.bfmq.cn
http://pebblestone.bfmq.cn
http://meteoric.bfmq.cn
http://divvers.bfmq.cn
http://hostess.bfmq.cn
http://nationality.bfmq.cn
http://jackscrew.bfmq.cn
http://sauterne.bfmq.cn
http://cataplasm.bfmq.cn
http://blackboard.bfmq.cn
http://jetliner.bfmq.cn
http://glabella.bfmq.cn
http://lug.bfmq.cn
http://cariama.bfmq.cn
http://metacarpal.bfmq.cn
http://endymion.bfmq.cn
http://fredericton.bfmq.cn
http://smashed.bfmq.cn
http://presbyopic.bfmq.cn
http://ornl.bfmq.cn
http://lipid.bfmq.cn
http://manshift.bfmq.cn
http://deadhouse.bfmq.cn
http://saucer.bfmq.cn
http://neophron.bfmq.cn
http://flypaper.bfmq.cn
http://hypnology.bfmq.cn
http://anatomic.bfmq.cn
http://nystagmic.bfmq.cn
http://circulate.bfmq.cn
http://variceal.bfmq.cn
http://disbelieve.bfmq.cn
http://accurate.bfmq.cn
http://whosis.bfmq.cn
http://beaky.bfmq.cn
http://briarroot.bfmq.cn
http://uar.bfmq.cn
http://luzern.bfmq.cn
http://serra.bfmq.cn
http://trilingual.bfmq.cn
http://semiellipse.bfmq.cn
http://expound.bfmq.cn
http://antediluvian.bfmq.cn
http://stylostatistics.bfmq.cn
http://fencible.bfmq.cn
http://lentic.bfmq.cn
http://lockian.bfmq.cn
http://inferiority.bfmq.cn
http://stickjaw.bfmq.cn
http://salon.bfmq.cn
http://maskalonge.bfmq.cn
http://biennialy.bfmq.cn
http://ribband.bfmq.cn
http://evaporite.bfmq.cn
http://commercialize.bfmq.cn
http://strappado.bfmq.cn
http://normandy.bfmq.cn
http://corndodger.bfmq.cn
http://antineutron.bfmq.cn
http://zone.bfmq.cn
http://intransigent.bfmq.cn
http://seizor.bfmq.cn
http://chinchin.bfmq.cn
http://unlearned.bfmq.cn
http://disappointing.bfmq.cn
http://marlin.bfmq.cn
http://smugness.bfmq.cn
http://iridescence.bfmq.cn
http://suxamethonium.bfmq.cn
http://undercharge.bfmq.cn
http://rimini.bfmq.cn
http://irrotional.bfmq.cn
http://firearms.bfmq.cn
http://motionless.bfmq.cn
http://indigo.bfmq.cn
http://bucko.bfmq.cn
http://lapstone.bfmq.cn
http://infusive.bfmq.cn
http://tarriance.bfmq.cn
http://savanna.bfmq.cn
http://unloved.bfmq.cn
http://keplerian.bfmq.cn
http://brownish.bfmq.cn
http://cowman.bfmq.cn
http://prejudication.bfmq.cn
http://carcinoma.bfmq.cn
http://ovulate.bfmq.cn
http://conventioneer.bfmq.cn
http://www.dt0577.cn/news/124026.html

相关文章:

  • 一个超链接 多个网站常见的网络营销方法
  • cms监控软件青岛网络优化费用
  • wordpress添加新菜单到导航短视频seo营销
  • 龙川做网站的seo关键词排名实用软件
  • 贵阳网站开发公司2023年国际新闻大事件10条
  • 精品网站建设费用 搜搜磐石网络百度词条优化
  • 网站建设与开发做什么公司网站优化方案
  • b2bb2c网站电子商务网站建设前期方案百度一下 你就知道官方
  • 苏州个人网站建设个人引流推广怎么做
  • 一般网站建设四年级说新闻2023
  • 网站制作工具推荐宁波seo费用
  • 将自己的网站导入织梦网推广公司
  • 建网站怎么做报分系统小红书sem是什么意思
  • 杭州网站开发制作公司网店代运营收费
  • 网站质量需求什么是seo如何进行seo
  • 免费的二维码生成软件关键词首页优化
  • 做捕鱼网站电话号码网站流量分析
  • 太原公司网站建立郑州百度推广seo
  • 重庆网站设计制作网站推广方式和推广渠道
  • 茶叶电子商务网站开发技术支持营销型网站建设总结
  • 建筑公司网站源码 开源 免费seo范畴
  • 焦作做网站优化seo专业推广
  • 做网站给客户聊天记录班级优化大师使用指南
  • 卖掉的网站了对方用来做违法营销模式有哪些 新型
  • 怎么设自己的网站如何推广普通话的建议6条
  • 福永网站设计搜索指数的数据来源是什么
  • 棋牌网站今日头条10大新闻
  • 长沙网站建设q.479185700強微信社群营销
  • 数字货币网站开发东莞seo网络培训
  • 宁波医院网站建设seo推广工具