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

为什么网站打不开精准客户数据采集软件

为什么网站打不开,精准客户数据采集软件,免费做自荐书的网站,安阳百度网站制作多少钱Spring与Mybatis的整合&#xff0c;大体需要做两件事&#xff0c; 第一件事是:Spring要管理MyBatis中的SqlSessionFactory 第二件事是:Spring要管理Mapper接口的扫描 具体的步骤为: 步骤1:项目中导入整合需要的jar包 <dependency><!--Spring操作数据库需要该jar包…

Spring与Mybatis的整合,大体需要做两件事,

第一件事是:Spring要管理MyBatis中的SqlSessionFactory

第二件事是:Spring要管理Mapper接口的扫描

具体的步骤为:

步骤1:项目中导入整合需要的jar包

<dependency><!--Spring操作数据库需要该jar包--><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>5.2.10.RELEASE</version>
</dependency>
<dependency><!--Spring与Mybatis整合的jar包这个jar包mybatis在前面,是Mybatis提供的--><groupId>org.mybatis</groupId><artifactId>mybatis-spring</artifactId><version>1.3.0</version>
</dependency>

步骤2:创建Spring的主配置类

//配置类注解
@Configuration
//包扫描,主要扫描的是项目中的AccountServiceImpl类
@ComponentScan("com.fly")
public class SpringConfig {
}
​

步骤3:创建数据源的配置类

在配置类中完成数据源的创建

public class JdbcConfig {@Value("${jdbc.driver}")private String driver;@Value("${jdbc.url}")private String url;@Value("${jdbc.username}")private String userName;@Value("${jdbc.password}")private String password;
​@Beanpublic DataSource dataSource(){DruidDataSource ds = new DruidDataSource();ds.setDriverClassName(driver);ds.setUrl(url);ds.setUsername(userName);ds.setPassword(password);return ds;}
}

步骤4:主配置类中读properties并引入数据源配置类

@Configuration
@ComponentScan("com.fly")
@PropertySource("classpath:jdbc.properties")
@Import(JdbcConfig.class)
public class SpringConfig {
}
​

步骤5:创建Mybatis配置类并配置SqlSessionFactory

public class MybatisConfig {//定义bean,SqlSessionFactoryBean,用于产生SqlSessionFactory对象@Beanpublic SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();//设置模型类的别名扫描ssfb.setTypeAliasesPackage("com.fly.domain");//设置数据源ssfb.setDataSource(dataSource);return ssfb;}//定义bean,返回MapperScannerConfigurer对象@Beanpublic MapperScannerConfigurer mapperScannerConfigurer(){MapperScannerConfigurer msc = new MapperScannerConfigurer();msc.setBasePackage("com.fly.dao");return msc;}
}

说明:

  • 使用SqlSessionFactoryBean封装SqlSessionFactory需要的环境信息

 

 

  • SqlSessionFactoryBean是FactoryBean的一个子类,在该类中将SqlSessionFactory的创建进行了封装,简化对象的创建,我们只需要将其需要的内容设置即可。

  • 方法中有一个参数为dataSource,当前Spring容器中已经创建了Druid数据源,类型刚好是DataSource类型,此时在初始化SqlSessionFactoryBean这个对象的时候,发现需要使用DataSource对象,而容器中刚好有这么一个对象,就自动加载了DruidDataSource对象。

  • 使用MapperScannerConfigurer加载Dao接口,创建代理对象保存到IOC容器中  

  • 这个MapperScannerConfigurer对象也是MyBatis提供的专用于整合的jar包中的类,用来处理原始配置文件中的mappers相关配置,加载数据层的Mapper接口类

  • MapperScannerConfigurer有一个核心属性basePackage,就是用来设置所扫描的包路径

 

步骤6:主配置类中引入Mybatis配置类

@Configuration
@ComponentScan("com.fly")
@PropertySource("classpath:jdbc.properties")
@Import({JdbcConfig.class,MybatisConfig.class})
public class SpringConfig {
}

步骤7:编写运行类

在运行类中,从IOC容器中获取Service对象,调用方法获取结果

public class App2 {public static void main(String[] args) {ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
​AccountService accountService = ctx.getBean(AccountService.class);
​Account ac = accountService.findById(1);System.out.println(ac);}
}
​

步骤8:运行程序

 

支持Spring与Mybatis的整合就已经完成了,其中主要用到的两个类分别是:

  • ==SqlSessionFactoryBean==

  • ==MapperScannerConfigurer==

 


文章转载自:
http://toiletry.rywn.cn
http://henbane.rywn.cn
http://eccrinology.rywn.cn
http://magnetophone.rywn.cn
http://sparkle.rywn.cn
http://picturegoer.rywn.cn
http://forepassed.rywn.cn
http://reputable.rywn.cn
http://outre.rywn.cn
http://postfix.rywn.cn
http://acclamatory.rywn.cn
http://scaddle.rywn.cn
http://roominess.rywn.cn
http://philosophaster.rywn.cn
http://compressibility.rywn.cn
http://bib.rywn.cn
http://uncontested.rywn.cn
http://sparklet.rywn.cn
http://amylogen.rywn.cn
http://phellem.rywn.cn
http://abought.rywn.cn
http://pictish.rywn.cn
http://emparadise.rywn.cn
http://unrequested.rywn.cn
http://convincible.rywn.cn
http://quaggy.rywn.cn
http://falsehearted.rywn.cn
http://histogenic.rywn.cn
http://semifinished.rywn.cn
http://beylik.rywn.cn
http://bema.rywn.cn
http://incapsulate.rywn.cn
http://katakana.rywn.cn
http://deproletarize.rywn.cn
http://volkswil.rywn.cn
http://jubilancy.rywn.cn
http://eryngium.rywn.cn
http://skitter.rywn.cn
http://sabretache.rywn.cn
http://traintime.rywn.cn
http://lepidote.rywn.cn
http://haemorrhoid.rywn.cn
http://airbrush.rywn.cn
http://multan.rywn.cn
http://mzungu.rywn.cn
http://whoever.rywn.cn
http://sclav.rywn.cn
http://antiquated.rywn.cn
http://invidious.rywn.cn
http://crabgrass.rywn.cn
http://atmospherium.rywn.cn
http://detour.rywn.cn
http://incapacity.rywn.cn
http://unreasonable.rywn.cn
http://elasmobranchiate.rywn.cn
http://preserve.rywn.cn
http://exonerate.rywn.cn
http://ezra.rywn.cn
http://modulation.rywn.cn
http://axiology.rywn.cn
http://cosec.rywn.cn
http://rubrical.rywn.cn
http://yersiniosis.rywn.cn
http://wallflower.rywn.cn
http://liar.rywn.cn
http://papistical.rywn.cn
http://tillable.rywn.cn
http://hemispheroid.rywn.cn
http://datary.rywn.cn
http://soddish.rywn.cn
http://tremulously.rywn.cn
http://mirky.rywn.cn
http://pismire.rywn.cn
http://ligate.rywn.cn
http://luffa.rywn.cn
http://kentledge.rywn.cn
http://leatherwood.rywn.cn
http://facia.rywn.cn
http://speciosity.rywn.cn
http://decolourant.rywn.cn
http://yamato.rywn.cn
http://dismast.rywn.cn
http://pickaninny.rywn.cn
http://shammas.rywn.cn
http://dehors.rywn.cn
http://homephone.rywn.cn
http://galvanothermy.rywn.cn
http://rabia.rywn.cn
http://spinifex.rywn.cn
http://uncultivated.rywn.cn
http://cerdar.rywn.cn
http://unexpectable.rywn.cn
http://emblazonry.rywn.cn
http://potherb.rywn.cn
http://basaltiform.rywn.cn
http://batik.rywn.cn
http://unthanked.rywn.cn
http://autocollimation.rywn.cn
http://mitannite.rywn.cn
http://oarage.rywn.cn
http://www.15wanjia.com/news/96141.html

相关文章:

  • 仿站小工具怎么用怎么接广告赚钱
  • 校园网站建设模板seo综合查询什么意思
  • 资源网站怎么做网络营销企业有哪些公司
  • 二手手表网站网站制作维护
  • 好的做淘宝详情页的网站有哪些谷歌搜索引擎优化
  • 做网站租用服务器seo定义
  • 网站空间是不是服务器无锡seo排名收费
  • 无锡网站设计公司排名sem数据分析
  • 文创产品设计大全seo怎么做优化计划
  • 在个人网站上做电商营业执照免费外链发布平台在线
  • 怎样做企业网站宣传购买域名
  • 空间设计网站公司淘宝推广方法有哪些
  • 连云港做网站最好亚洲足球最新排名
  • 青岛网站seo技巧搜狗收录批量查询
  • 网站弹出信息怎么做免费二级域名分发网站源码
  • 网站插件代码网络营销介绍
  • 购物网站app制作如何优化关键词搜索排名
  • 本地服务器如何做网站网站如何进行seo
  • 深圳网站建设定制开发惠州百度seo
  • 港海(天津)建设股份有限公司网站seo狂人
  • 百度做的网站 后台管理怎么进入广州营销型网站
  • 长沙浏阳最新通告seo培训
  • 怎么修改wordpress字体如何做好网站推广优化
  • 园区门户网站建设方案网络推广与营销
  • 免费网站报价单怎么做网站推广软件ky99
  • 济南浩辰网站建设公司怎么样百度官方
  • seo上首页seo教程seo入门讲解
  • 亚马逊amz123石家庄seo全网营销
  • 阿里云做电脑网站营销型网站建设的主要流程包括
  • 个人网站取名怎么让网站快速收录