1 Star 4 Fork 1

xbatis/xbatis-spring-boot-parent

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
Ai东-Ai-010 Ai东 1.8.9 4965c11 19天前
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

xbatis-spring-boot-parent

介绍

xbatis springboot启动器,基于mybatis-spring-boot-starter改动,改动很小,只是替换成xbatis的配置类

快速开始

1. 基于spring-boot开发 (已引入spring、springboot 基本依赖,创建SpringApplication.run即可启动)

1.1 springboot2 maven 集成

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>cn.xbatis</groupId>
            <artifactId>xbatis-spring-boot-parent</artifactId>
            <version>1.8.9</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>cn.xbatis</groupId>
        <artifactId>xbatis-spring-boot-starter</artifactId>
    </dependency>
</dependencies>

1.2 springboot3 maven 集成

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>cn.xbatis</groupId>
            <artifactId>xbatis-spring-boot-parent</artifactId>
            <version>1.8.9-spring-boot3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>cn.xbatis</groupId>
        <artifactId>xbatis-spring-boot-starter</artifactId>
    </dependency>
</dependencies>

1.3 数据源 配置

配置spring boot配置文件

spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass

或者 自己实例一个 DataSource 也可以


@Configuration(proxyBeanMethods = false)
public class DatasourceConfig {

    @Bean
    public DataSource getDataSource() {
        return new EmbeddedDatabaseBuilder()
                .setName("test_db")
                .setType(EmbeddedDatabaseType.H2)
                .addScript("schema.sql")
                .build();
    }
}

其他配置(可不配置)

数据库命名规则配置(可不配置,在项目启动时配置)


@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        MybatisMpConfig.setTableUnderline(true); //数据库表是否下划线规则 默认 true
        MybatisMpConfig.setColumnUnderline(true); ///数据库列是否下划线规则 默认 true
        SpringApplication.run(DemoApplication.class, args);
    }
}

数据库类型配置(可不配置,默认MYSQL)

mybatis:
  configuration:
    databaseId: MYSQL

更多数据库支持,请查看类:db.sql.api.DbType

启动springboot即可,非常简单

一切都就绪,启动即可

1.添加此依赖,无需再添加mybatis依赖

2.包含 mybatis、mybatis-spring、 mybatis-spring-boot-starter 所有功能(支持原有mybatis的所有功能)

3.更多mybatis 配置参数,参考 https://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/zh_CN/index.html

4.参考示例:https://gitee.com/xbatis/xbatis/tree/master/xbatis-spring-boot-demo

5.更多 mybatis 用法,参考: mybatis:https://mybatis.org/mybatis-3/zh_CN/index.html

mybatis spring: https://mybatis.org/spring/zh_CN/index.html

6.更多xbatis 用法,参考作者编写的test case:(包含各种简单,复杂的CRUD操作案例)

https://gitee.com/xbatis/xbatis/tree/master/xbatis-core/src/test/java/com/mybatis/mp/core/test/testCase

空文件

简介

xbatis之springboot启动器 展开 收起
README
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/xbatis/xbatis-spring-boot-parent.git
git@gitee.com:xbatis/xbatis-spring-boot-parent.git
xbatis
xbatis-spring-boot-parent
xbatis-spring-boot-parent
springboot3

搜索帮助