若依前后端分离版使用mybatis-plus实践教程

1、根目录得pom加入依赖

<properties>
    <mybatis-plus.version>3.5.1mybatis-plus.version>
properties>
<dependencies>
   
   <dependency>
       <groupId>com.baomidougroupId>
       <artifactId>mybatis-plus-boot-starterartifactId>
       <version>${mybatis-plus.version}version>
   dependency>
dependencies>

2、在framework得pom文件下面增加

        
        <dependency>
            <groupId>com.baomidougroupId>
            <artifactId>mybatis-plus-boot-starterartifactId>
        dependency>

3、在framework的config下面更改myBatisConfig

/*    @Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
    {
        String typeAliasesPackage = env.getProperty("mybatis.typeAliasesPackage");
        String mapperLocations = env.getProperty("mybatis.mapperLocations");
        String configLocation = env.getProperty("mybatis.configLocation");
        typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
        VFS.addImplClass(SpringBootVFS.class);

        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
        sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
        sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
        return sessionFactory.getObject();
    }*/
    @Bean
    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception
    {
        String typeAliasesPackage = env.getProperty("mybatis-plus.typeAliasesPackage");
        String mapperLocations = env.getProperty("mybatis-plus.mapperLocations");
        String configLocation = env.getProperty("mybatis-plus.configLocation");
        typeAliasesPackage = setTypeAliasesPackage(typeAliasesPackage);
        VFS.addImplClass(SpringBootVFS.class);

        final MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
        sessionFactory.setTypeAliasesPackage(typeAliasesPackage);
        sessionFactory.setMapperLocations(resolveMapperLocations(StringUtils.split(mapperLocations, ",")));
        sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
        return sessionFactory.getObject();
    }

4、admin模块下面的yml配置

# MyBatis配置
#mybatis:
  ## 搜索指定包别名
  #typeAliasesPackage: com.qilaike.**.domain
  ## 配置mapper的扫描,找到所有的mapper.xml映射文件
  #mapperLocations: classpath*:mapper/**/*Mapper.xml
  ## 加载全局的配置文件
  #configLocation: classpath:mybatis/mybatis-config.xml
# MyBatis-plus配置
mybatis-plus:
  # 实体扫描,多个package用逗号或者分号分隔
  typeAliasesPackage: com.qilaike.**.domain
  # 对应的 XML 文件位置
  mapperLocations: classpath*:mapper/**/*Mapper.xml
  # 加载全局的配置文件
  configLocation: classpath:mybatis/mybatis-config.xml

  configuration:
    cache-enabled: true
    use-generated-keys: true
    default-executor-type: simple
    log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl

你可能感兴趣的:(mybatis,java,mybatis-plus)