springboot整合mybatis拦截器分页,意外收获字节跳动内部资料


spring:

  application:

    name: spring-cloud-dynamic

  datasource:

    #类型

    type: com.alibaba.druid.pool.DruidDataSource

    driver-class-name: com.mysql.cj.jdbc.Driver

    url: jdbc:mysql://localhost:3306/f2f?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai

    username: root

    password: 



    initial-size: 2

    max-idle: 10

    min-idle: 1

    max-wait: 60000

    max-active: 20 #最大空闲连接数

    #多久进行一次检测,检测需要关闭的空闲连接

    time-between-eviction-tuns-millis: 60000 

MybatisConfig



/**

 * @author lanys

 * @Description:

 * @date 23/7/2021 下午8:38

 */



@Configuration

@EnableTransactionManagement

@PropertySource(value = "classpath:application.yml", ignoreResourceNotFound = true)

public class MybatisConfig implements TransactionManagementConfigurer {



    @Value("${mybatis.mapper-locations}")

    private String mapper;



    @Value("${mybatis.type-aliases-package}")

    private String aliases;



    @Autowired

    private DataSource dataSource;



    @Bean(name = "sqlSessionFactory")

    public SqlSessionFactory sqlSessionFactory() throws Exception {

        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();

        // 设置数据源

        bean.setDataSource(dataSource);

        // 设置xml

        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapper));

        // 设置别名

        bean.setTypeAliasesPackage(aliases);

        // 添加分页插件

        bean.setPlugins(new Interceptor[]{pageInterceptor()});

        bean.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);

        return bean.getObject();

    }



    /**

     * 分页拦截器

     * @return

     */

    private PageInterceptor pageInterceptor() {

        PageInterceptor pageInterceptor = new PageInterceptor();

        // 详见 com.github.pagehelper.page.PageParams

        Properties p = new Properties();

        // RowBounds是否进行count查询 - 默认不查询

        p.setProperty("rowBoundsWithCount", "true");

        // 当设置为true的时候,如果page size设置为0(或RowBounds的limit=0),就不执行分页,返回全部结果

        p.setProperty("pageSizeZero", "true");

        // 分页合理化

        p.setProperty("reasonable", "false");

        // 是否支持接口参数来传递分页参数,默认false

        p.setProperty("supportMethodsArguments", "true");

        // 设置数据库方言 , 也可以不设置,会动态获取

        p.setProperty("helperDialect", "mysql");

        pageInterceptor.setProperties(p);

        return pageInterceptor;

    }



    @Override

    public PlatformTransactionManager annotationDrivenTransactionManager() {

        return new DataSourceTransactionManager(dataSource);

    }

} 

测试


自己的其中代码


/**

     * 关注列表

     * @param userId

     * @param page

     * @param size

     * @return

     */

    @Override

    public List<DynamicInfo> focusList(Long userId, Integer page, Integer size) {

        PageHelper.startPage(page, size);



        List<DynamicInfo> listByUserId = new ArrayList<>();

        try {

            //获取自己关注列表

            listByUserId = this.dynamicReleaseMapper.getListFocusId(userId);

            if (listByUserId == null || listByUserId.size() == 0){

                return listByUserId;

            }

            //List<DynamicInfo> listByUserId = this.dynamicReleaseMapper.getListFocusId(userId).stream().filter(x->(x.getIsPicture()!=2 && x.getIsVideo() !=2)||(x.getIsPicture()==2 && x.getIsVideo() !=2)||(x.getIsPicture()!=2 && x.getIsVideo() ==2)).collect(Collectors.toList());

            publicGetDynamicInfo(userId,listByUserId);

            //}

            log.info("-------获取关注列表-------");



### 最后

手绘了下图所示的kafka知识大纲流程图(xmind文件不能上传,导出图片展现),但都都可提供源文件给每位爱学习的朋友

**[CodeChina开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频】](https://codechina.csdn.net/m0_60958482/java-p7)**

![image.png](https://img-blog.csdnimg.cn/img_convert/61513742ecee79ceb1146e70db5c8f91.png)

---获取关注列表-------");



### 最后

手绘了下图所示的kafka知识大纲流程图(xmind文件不能上传,导出图片展现),但都都可提供源文件给每位爱学习的朋友

**[CodeChina开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频】](https://codechina.csdn.net/m0_60958482/java-p7)**

[外链图片转存中...(img-uAc0fCIF-1630915380014)]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值