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

论述农产品电商网站建设静态旅游网站

论述农产品电商网站建设,静态旅游网站,成都seo优化外包公司,wordpress 列表函数文章目录 目录 文章目录 前言 一、依赖和目录结构 二、使用步骤 2.1 两个数据源的不同引用配置 2.2 对应的mapper 2.3 定时任务处理 总结 前言 一、依赖和目录结构 dependenciesdependencygroupIdorg.springframework.boot/groupIdartifa… 文章目录 目录 文章目录 前言 一、依赖和目录结构 二、使用步骤 2.1 两个数据源的不同引用配置 2.2 对应的mapper 2.3 定时任务处理  总结 前言 一、依赖和目录结构 dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactIdversion2.3.12.RELEASE/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactIdversion2.3.12.RELEASE/version/dependencydependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.5.1/version/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion5.1.49/version/dependency/dependencies 配置文件 server:port: 8089spring:datasource:remote :driver-class-name: com.mysql.jdbc.Driverjdbc-url: jdbc:mysql://192.168.31.2/student?useUnicodetruecharacterEncodingUTF-8useSSLfalseserverTimezoneUTCusername: rootpassword: 111local :driver-class-name: com.mysql.jdbc.Driverjdbc-url: jdbc:mysql://192.168.31.1/student?useUnicodetruecharacterEncodingUTF-8useSSLfalseserverTimezoneUTCusername: rootpassword: 111mybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启sql日志二、使用步骤 2.1 两个数据源的不同引用配置 package com.config;import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;import javax.annotation.Resource; import javax.sql.DataSource;/**** date Created in 2023/12/2 19:51* description本地数据源* modified By* version:*/ Configuration MapperScan(basePackages com.local.Mapper, sqlSessionTemplateRef sqlSessionTemplate1) public class MybatisLocalConfig {BeanConfigurationProperties(prefix spring.datasource.local)public DataSource dataSource1() {return DataSourceBuilder.create().build();}Beanpublic SqlSessionFactory sqlSessionFactory1(Qualifier(dataSource1) DataSource dataSource) throws Exception {MybatisSqlSessionFactoryBean factoryBean new MybatisSqlSessionFactoryBean();factoryBean.setDataSource(dataSource);// 设置mapper.xml文件的位置factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(classpath*:localmapper/*.xml));return factoryBean.getObject();}Beanpublic SqlSessionTemplate sqlSessionTemplate1(Qualifier(sqlSessionFactory1) SqlSessionFactory sqlSessionFactory) {return new SqlSessionTemplate(sqlSessionFactory);}} Configuration MapperScan(basePackages com.remote.Mapper, sqlSessionTemplateRef sqlSessionTemplate2) public class MybatisRemoteConfig {BeanConfigurationProperties(prefix spring.datasource.remote)public DataSource dataSource2() {return DataSourceBuilder.create().build();}Beanpublic SqlSessionFactory sqlSessionFactory2(Qualifier(dataSource2) DataSource dataSource) throws Exception {MybatisSqlSessionFactoryBean factoryBean new MybatisSqlSessionFactoryBean();factoryBean.setDataSource(dataSource);// 设置mapper.xml文件的位置factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(classpath*:mapper2/*.xml));return factoryBean.getObject();}Beanpublic SqlSessionTemplate sqlSessionTemplate2(Qualifier(sqlSessionFactory2) SqlSessionFactory sqlSessionFactory) {return new SqlSessionTemplate(sqlSessionFactory);} } 2.2 对应的mapper public interface CourseOneMapper extends BaseMapperCourse { }public interface CourseTwoMapper extends BaseMapperCourse {/*** 批量插入* param list*/Insert(script INSERT INTO tbl_course (name, teacher) VALUES foreach collectionlist itemitem separator, (#{item.name}, #{item.teacher}) /foreach /script)void batchInsert(Param(list) ListCourse list); }TableName(tbl_course) public class Course {TableId(type IdType.AUTO)private Integer id;private String name;private String teacher;public Course() {}public Course(Integer id, String name, String teacher) {this.id id;this.name name;this.teacher teacher;}/*** 获取* return id*/public Integer getId() {return id;}/*** 设置* param id*/public void setId(Integer id) {this.id id;}/*** 获取* return name*/public String getName() {return name;}/*** 设置* param name*/public void setName(String name) {this.name name;}/*** 获取* return teacher*/public String getTeacher() {return teacher;}/*** 设置* param teacher*/public void setTeacher(String teacher) {this.teacher teacher;}Overridepublic String toString() {return Course{id id , name name , teacher teacher };} } 2.3 定时任务处理  EnableScheduling //开启定时 Component public class MySchedule {Resourceprivate CourseOneMapper courseOneMapper;Resourceprivate CourseTwoMapper courseTwoMapper;/*** 每隔10秒执行一次*/Scheduled(fixedDelay 1000000)public void test(){//查询到要同步的数据ListCourse coursesOne courseOneMapper.selectList(null);//批量插入courseTwoMapper.batchInsert(coursesOne);}} 总结
http://wiki.neutronadmin.com/news/376726/

相关文章:

  • 个人网站开发实例wordpress企业微信
  • 电商网站开发分析如何查网站备案信息
  • 网站设计排行mip wordpress模板
  • 优秀网站建设多少钱什么网站能赚钱
  • 网站建设 教学大纲软件工程师的薪资待遇
  • 涉密项目单位网站建设流程wordpress备案号链接错误
  • 怀化网站优化哪个好邯郸wap网站建设费用
  • 网站关键词密这么稀释视频源网站怎么做
  • 北京设计网站建设易用的做网站软件
  • 惠州免费自助建站模板logo设计网站国外
  • ios手机网站建设东莞网络推广代理
  • 中企动力做的网站被百度屏蔽哪些网站可以做招生信息
  • 太仓网站优化wordpress搭建像册
  • 做互助盘网站多少钱ftp网站备份
  • 莱州市双语网站深圳品牌设计公司招聘
  • 呼和浩特建站要怎么做网络营销
  • 做网站时候图片和视频放在哪里网站页面设计和结构的技巧
  • 响应式网站 尺寸wap自助建站排板
  • 网站开发保密协议书全flash网站源码
  • dede wordpress广州建站优化公司
  • 辽宁网站建设企业五莲县财源建设网站
  • 网站建设及推广前端开发和网站建设
  • 郴州网站建设公司在哪里软件销售公司排名
  • 同城网站深圳有哪些网络公司
  • 什么网站可以做直播哪个网站可以做危险化学品供求
  • 网站标签怎么设置做海报的网站有哪些内容
  • 甜点网站要怎么做专做农产品跨境的网站有
  • 做水处理药剂的公司网站海南房产信息网
  • 企业做门户网站的重要性工业互联网平台分类
  • 如何建立网站和网页设计签名免费网站