spring boot 项目重新搭建----------分页及通用mapper配置

1.在resources下创建favicon.ico(访问的时候会有自己的小图标)

spring boot 项目重新搭建----------分页及通用mapper配置_第1张图片

2.在yml中@var@  

#当前服务器版本 自动读取MAVEN信息 @var@格式
version: @project.version@

3配置分页插件

导入依赖



    com.github.pagehelper
    pagehelper
    4.1.6
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("sqlDataSource") DataSource dataSource) throws Exception {
    final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
    sessionFactory.setDataSource(dataSource);
    //添加分页插件
    sessionFactory.setPlugins(plugins());
    org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration();
    config.setCallSettersOnNulls(settings.isCallSettersOnNulls());
    sessionFactory.setConfiguration(config);
    return sessionFactory.getObject();
}

private Interceptor[] plugins() {
    //分页插件设置
    PageHelper pageHelper = new PageHelper();
    Properties properties = new Properties();
    properties.setProperty("reasonable", "true");
    properties.setProperty("supportMethodsArguments", "true");
    properties.setProperty("returnPageInfo", "check");
    properties.setProperty("params", "count=countSql");
    pageHelper.setProperties(properties);
    return new Interceptor[]{pageHelper};
}

设置插件配置后,

PageHelper.startPage(pageNum,paegSize);

4.配置通用mapper



    tk.mybatis
    mapper-spring-boot-starter
    2.0.4

    org.mybatis.generator
    mybatis-generator-maven-plugin
    1.3.6
    
        
            ${basedir}/src/main/resources/generatorConfig.xml
        
        true
        true
    
    
        
            mysql
            mysql-connector-java
            5.1.29
        
        
            tk.mybatis
            mapper
            4.0.0
        
    

配置对应的generatorConfig.xml文件

.yml配置

#通用mapper
mapper:
  mappers: tk.mybatis.mapper.common.Mapper
  notEmpty: true

扫描器换成tk的

@tk.mybatis.spring.annotation.MapperScan

 maven命令 

mybatis-generator:generate

 

 

 

 

 

 

 

你可能感兴趣的:(spring,boot)