闲谈 mybatis-plus 3

MybatisPlus简介

MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。

插件安装与配置

打开idea的Settings—》Plugins—》Marketplace,搜索MybatisPlus,安装并重启

配置数据库相关参数

 选中Other菜单,会出现Config Database(配置数据库)和Code Generator(代码生成)

选中要生成的表,并根据具体情况修改相关配置,最后点击右下角code generatro生成代码

导入依赖:mybatis-plus-boot-starter

        
            com.baomidou
            mybatis-plus-boot-starter
            3.5.0
        

        
            com.baomidou
            mybatis-plus-boot-starter-test
            3.5.3.1
        

数据库连接

        
            mysql
            mysql-connector-java
            8.0.19
        
spring.datasource.driver-class-name= com.mysql.jdbc.Driver
spring.datasource.url= jdbc:mysql://localhost:3306/explore?characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8
spring.datasource.username= root
spring.datasource.password= root

配置数据源

@Configuration
@MapperScan(basePackages = "com.***.mapper")
public class MyBatisConfig {


    @Bean(name = "sqlSessionFactory")
    @Primary
    public SqlSessionFactory sqlSessionFactory(@Qualifier("dataSource") DataSource datasource) throws Exception {
        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
        bean.setDataSource(datasource);
        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapper/*.xml"));
        return bean.getObject();
    }

}

你可能感兴趣的:(MyBatis-Plus,mybatis,java,spring)