Springboot+mybatisplus+多数据源

之前一篇讲了vue2.0的框架搭建,本篇主要讲后台使用springboot+mybatisplus.
在springboot项目中引入mybatisplus,需要在pom.xml加入

<dependency>
		<groupId>com.baomidou</groupId>
		<artifactId>mybatis-plus-boot-starter</artifactId>
		<version>3.4.1</version>
</dependency>

我们需要写一个类启动springboot

@SpringBootApplication
public class Application{
   

	public static void main(String[] args) {
   
		
		SpringApplication.run(Application.class, args);
	}
}

这个类放在classpath的根目录下
之后建立Dao接口类需要继承自com.baomidou.mybatisplus.core.mapper.BaseMapper
这个是Dao层的基类,我们每次操作Dao层都需要继承这个类,这个类里的增删改查操作都已经封装好了,我们只需要拿来用,以下是这个接口类的源码

package com.baomidou.mybatisplus.core.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
 * Mapper 缁ф壙璇ユ帴鍙e悗锛屾棤闇�缂栧啓 mapper.xml 鏂囦欢锛屽嵆鍙幏寰桟RUD鍔熻兘
 * <p>杩欎釜 Mapper 鏀寔 id 娉涘瀷</p>
 *
 * @author hubin
 * @since 2016-01-23
 */
public interface BaseMapper<T> extends Mapper<T> {
   

    int insert(T entity);

    int deleteById(Serializable id);

    int deleteByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);
    
    int delete(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

    int deleteBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);

    int updateById(@Param(Constants.ENTITY) T entity);

    int update(@Param(Constants.ENTITY) T entity, @Param(Constants.WRAPPER) Wrapper<T> updateWrapper);

    T selectById(Serializable id);

    List<T> selectBatchIds(@Param(Constants.COLLECTION) Collection<? extends Serializable> idList);

    List<T> selectByMap(@Param(Constants.COLUMN_MAP) Map<String, Object> columnMap);

    T selectOne(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);


    Integer selectCount(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

    List<T> selectList(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);
    
    List<Map<String, Object>> selectMaps(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper);

    List<Object> selectObjs(@Param(Constants
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
SpringBoot可以使用MyBatis-Plus实现多数据源配置。多数据源配置是指在一个应用中配置多个数据库连接,并能够根据需要选择使用哪个数据库。通过MyBatis-Plus,可以方便地配置和使用多个数据源。 在配置多数据源时,可以使用MyBatis-Plus提供的注解和配置类来实现。可以根据需要配置多个数据源,每个数据源对应一个数据库。例如,可以配置MySQL数据库、PostgreSQL数据库和Doris数据库作为不同的数据源。 具体配置方法可以参考引用和引用中提到的文章。这些文章详细介绍了如何在SpringBoot中整合MyBatis-Plus并配置动态数据源。你可以根据这些文章的参考来配置你的多数据源。 在配置完成后,你可以根据需要在代码中选择使用哪个数据源进行数据库操作。通过配置多数据源,你可以在一个应用中同时操作多个数据库,方便实现复杂的业务逻辑。 总之,SpringBootMyBatis-Plus提供了方便的方式来配置和使用多数据源,可以满足在一个应用中操作多个数据库的需求。你可以参考相关文档并按照需求进行配置和使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [【应用】SpringBoot -- 基于 MyBatis-Plus 实现多数据源配置](https://blog.csdn.net/zqf787351070/article/details/127775519)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [SpringBoot整合MyBatisPlus配置动态数据源的方法](https://download.csdn.net/download/weixin_38659646/12749115)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不知道明天和天明

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值