Skip to content

Configuration

Integrating MyBatis-Plus is very simple. We only need some basic configuration to leverage the powerful features of MyBatis-Plus!

Spring Boot Application

  • Configure the MapperScan annotation

    @SpringBootApplication
    @MapperScan("com.baomidou.mybatisplus.samples.quickstart.mapper")
    public class Application {
    public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
    }
    }

Spring Application

  • Configure MapperScan

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.baomidou.mybatisplus.samples.quickstart.mapper"/>
    </bean>
  • Adjust SqlSessionFactory to MyBatis-Plus’s SqlSessionFactory

    <bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    </bean>

Typically, for simple projects, the configurations above are sufficient to use MyBatis-Plus normally. For specific examples, refer to the following projects: Spring Boot Quick Start Sample, Spring MVC Quick Start Sample.

Additionally, MyBatis-Plus provides numerous personalized configurations to meet the needs of projects with varying complexities. You can choose them according to your project requirements. For detailed configuration, please refer to the Using Configuration article.

For complex table structures, we also offer a rich set of field annotations to meet your special needs. For details, please refer to the Annotations article.

Baomidou

© 2016-2025 Baomidou™. All Rights Reserved.

Power by Astro Starlight | Sponsored by JetBrains

渝ICP备2021000141号-1 | 渝公网安备50011302222097