一起来学 SpringBoot 2.x | 第八篇:通用 Mapper 与分页插件的集成

【SpringBoot3】Spring Boot 3.0 集成 Mybatis Plus MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。 阅读详情

点击上方“芋道源码”,选择“置顶公众号”

技术文章第一时间送达!

源码精品专栏

 

摘要: 原创出处 http://blog.battcn.com/2018/05/10/springboot/v2-orm-mybatis-plugin/ 「唐亚峰」欢迎转载,保留摘要,谢谢!

  • 插件介绍

  • 导入依赖

  • 属性配置

  • 具体编码

  • 说点什么


SpringBoot是为了简化Spring` 应用的创建、运行、调试、部署等一系列问题而诞生的产物,自动装配的特性让我们可以更好的关注业务本身而不是外部的XML配置,我们只需遵循规范,引入相关的依赖就可以轻易的搭建出一个 WEB 工程

在一起来学SpringBoot | 第七篇:整合Mybatis一文中,我们介绍了Mybatis这款优秀的框架,顺便提及了民间大神开发的两款插件(通用Mapper、PageHelper),从此告别简单CURD代码的编写….

插件介绍

以下两款插件作者均是同一个人,如果你想深入了解Mybatis以及插件开发可以购买作者的书籍

  • 京东: https://item.jd.com/12103309.html

  • 当当: http://product.dangdang.com/25098208.html

分页插件

  • GIT地址: https://github.com/pagehelper/Mybatis-PageHelper

在没有分页插件之前,写一个分页需要两条SQL语句,一条查询一条统计,然后才能计算出页码,这样的代码冗余而又枯燥,更重要的一点是数据库迁移,众所周知不同的数据库分页写法是不同的,而Mybatis不同于Hibernate的是它只提供动态SQL和结果集映射。值得庆幸的是,它虽然没有为分页提供良好的解决方案,但却提供了Interceptor以供开发者自己扩展,这也是这款分页插件的由来….

通用Mapper

  • GIT地址: https://gitee.com/free/Mapper

通用 Mapper 是一个可以实现任意 MyBatis 通用方法的框架,项目提供了常规的增删改查操作以及 Example 相关的单表操作。通用 Mapper 是为了解决 MyBatis 使用中 90% 的基本操作,使用它可以很方便的进行开发,可以节省开发人员大量的时间。

导入依赖

在 pom.xml 中添加通用Mapper与分页插件的依赖包

<!-- 通用Mapper插件
 文档地址:https://gitee.com/free/Mapper/wikis/Home -->
<dependency>
    <groupId>tk.mybatis</groupId>
    <artifactId>mapper-spring-boot-starter</artifactId>
    <version>2.0.2</version>
</dependency>
<!-- 分页插件
 文档地址:https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md -->
<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper-spring-boot-starter</artifactId>
    <version>1.2.5</version>
</dependency>
<!-- MYSQL包 -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 默认就内嵌了Tomcat 容器,如需要更换容器也极其简单-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 测试包,当我们使用 mvn package 的时候该包并不会被打入,因为它的生命周期只在 test 之内-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

属性配置

在 application.properties 文件中分别添加上数据库、Mybatis、通用Mapper、PageHelper的属性配置,这里只提供了常见场景的配置,更全的配置可以参考上文所述的文文档(#^.^#)

spring.datasource.url=jdbc:mysql://localhost:3306/chapter7?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
spring.datasource.password=root
spring.datasource.username=root
# 如果想看到mybatis日志需要做如下配置
logging.level.com.battcn=DEBUG
######### Mybatis 自身配置 ##########
mybatis.mapper-locations=classpath:com/battcn/mapper/*.xml
mybatis.type-aliases-package=com.battcn.entity
# 驼峰命名规范 如:数据库字段是  order_id 那么 实体字段就要写成 orderId
mybatis.configuration.map-underscore-to-camel-case=true
######### 通用Mapper ##########
# 主键自增回写方法,默认值MYSQL,详细说明请看文档
mapper.identity=MYSQL
mapper.mappers=tk.mybatis.mapper.common.BaseMapper
# 设置 insert 和 update 中,是否判断字符串类型!=''
mapper.not-empty=true
# 枚举按简单类型处理
mapper.enum-as-simple-type=true
######### 分页插件 ##########
pagehelper.helper-dialect=mysql
pagehelper.params=count=countSql
pagehelper.reasonable=false
pagehelper.support-methods-arguments=true

通用Mapper

  • mapper.enum-as-simple-type: 枚举按简单类型处理,如果有枚举字段则需要加上该配置才会做映射

  • mapper.not-empty: 设置以后,会去判断 insert 和 update 中符串类型!=’’

分页插件

  • pagehelper.reasonable: 分页合理化参数,默认值为false。当该参数设置为 true 时,pageNum<=0 时会查询第一页, pageNum>pages(超过总数时),会查询最后一页。默认false 时,直接根据参数进行查询。

  • support-methods-arguments: 支持通过 Mapper 接口参数来传递分页参数,默认值false,分页插件会从查询方法的参数值中,自动根据上面 params 配置的字段中取值,查找到合适的值时就会自动分页。

注意事项

由于 mybatis.mapper-locations=classpath:com/battcn/mapper/*.xml配置的在java package中,而Spring Boot默认只打入java package -> *.java,所以我们需要给pom.xml文件添加如下内容

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
            <filtering>true</filtering>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

具体编码

完成基本配置后,接下来进行具体的编码操作。

表结构

创建一张 t_user 的表

CREATE TABLE `t_user` (
  `id` int(8) NOT NULL AUTO_INCREMENT COMMENT '主键自增',
  `username` varchar(50) NOT NULL COMMENT '用户名',
  `password` varchar(50) NOT NULL COMMENT '密码',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';

实体类

通用Mapper采用了JPA规范包中的注解,这种的设计避免了重复造轮子,更是让Spring Data Jpa的应用可以轻松切换到Mybatis

package com.battcn.entity;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * @author Levin
 * @since 2018/5/10 0007
 */
@Table(name = "t_user")
public class User implements Serializable {

    private static final long serialVersionUID = 8655851615465363473L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String username;
    private String password;
    // TODO  省略get set
}

持久层

为了更好的让熟悉它,此处模拟了一个自定义的SQL,可以发现使用 通用Mapper 后并不会破坏原有代码结构

UserMapper

继承 BaseMapper<T> 就可以了,这点是不是有点类似 JpaRepository,同时也可以根据自己需要扩展出更适合自己项目的BaseMapper,它的灵活也是众多开发者喜爱的因素之一

package com.battcn.mapper;

import com.battcn.entity.User;
import org.apache.ibatis.annotations.Mapper;
import tk.mybatis.mapper.common.BaseMapper;

/**
 * t_user 操作,继承 BaseMapper<T> 就可以了,是不是有点类似 JpaRepository
 *
 * @author Levin
 * @since 2018/5/10 0007
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 根据用户名统计(TODO 假设它是一个很复杂的SQL)
     *
     * @param username 用户名
     * @return 统计结果
     */
    int countByUsername(String username);
}

UserMapper 映射文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.battcn.mapper.UserMapper">

  <select id="countByUsername" resultType="java.lang.Integer">
      SELECT count(1) FROM t_user WHERE username = #{username}
  </select>
</mapper>

测试

完成数据访问层接口后,编写一个junit测试类来检验代码的正确性。

package com.battcn;

import com.battcn.entity.User;
import com.battcn.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * @author Levin
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class Chapter7ApplicationTests {

    private static final Logger log = LoggerFactory.getLogger(Chapter7ApplicationTests.class);

    @Autowired
    private UserMapper userMapper;

    @Test
    public void test1() throws Exception {
        final User user1 = new User("u1", "p1");
        final User user2 = new User("u1", "p2");
        final User user3 = new User("u3", "p3");
        userMapper.insertSelective(user1);
        log.info("[user1回写主键] - [{}]", user1.getId());
        userMapper.insertSelective(user2);
        log.info("[user2回写主键] - [{}]", user2.getId());
        userMapper.insertSelective(user3);
        log.info("[user3回写主键] - [{}]", user3.getId());
        final int count = userMapper.countByUsername("u1");
        log.info("[调用自己写的SQL] - [{}]", count);

        // TODO 模拟分页
        userMapper.insertSelective(new User("u1", "p1"));
        userMapper.insertSelective(new User("u1", "p1"));
        userMapper.insertSelective(new User("u1", "p1"));
        userMapper.insertSelective(new User("u1", "p1"));
        userMapper.insertSelective(new User("u1", "p1"));
        userMapper.insertSelective(new User("u1", "p1"));
        userMapper.insertSelective(new User("u1", "p1"));
        userMapper.insertSelective(new User("u1", "p1"));
        userMapper.insertSelective(new User("u1", "p1"));
        userMapper.insertSelective(new User("u1", "p1"));
        // TODO 分页 + 排序 this.userMapper.selectAll() 这一句就是我们需要写的查询,有了这两款插件无缝切换各种数据库
        final PageInfo<Object> pageInfo = PageHelper.startPage(1, 10).setOrderBy("id desc").doSelectPageInfo(() -> this.userMapper.selectAll());
        log.info("[lambda写法] - [分页信息] - [{}]", pageInfo.toString());

        PageHelper.startPage(1, 10).setOrderBy("id desc");
        final PageInfo<User> userPageInfo = new PageInfo<>(this.userMapper.selectAll());
        log.info("[普通写法] - [{}]", userPageInfo);
    }
}

总结

  1. Mybatis官方文档: http://www.mybatis.org/mybatis-3/zh/index.html

  2. 通用Mapper文档: https://gitee.com/free/Mapper/wikis/1.1-java?parent=1.integration

  3. 分页插件文档: https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md

目前很多大佬都写过关于 SpringBoot 的教程了,如有雷同,请多多包涵,本教程基于最新的 spring-boot-starter-parent:2.0.1.RELEASE编写,包括新版本的特性都会一起介绍…

说点什么

全文代码:https://github.com/battcn/spring-boot2-learning/tree/master/chapter7

666. 彩蛋



如果你对 Dubbo 感兴趣,欢迎加入我的知识星球一起交流。


知识星球

目前在知识星球(https://t.zsxq.com/2VbiaEu)更新了如下 Dubbo 源码解析如下:

01. 调试环境搭建
02. 项目结构一览
03. 配置 Configuration
04. 核心流程一览

05. 拓展机制 SPI

06. 线程池

07. 服务暴露 Export

08. 服务引用 Refer

09. 注册中心 Registry

10. 动态编译 Compile

11. 动态代理 Proxy

12. 服务调用 Invoke

13. 调用特性 

14. 过滤器 Filter

15. NIO 服务器

16. P2P 服务器

17. HTTP 服务器

18. 序列化 Serialization

19. 集群容错 Cluster

20. 优雅停机

21. 日志适配

22. 状态检查

23. 监控中心 Monitor

24. 管理中心 Admin

25. 运维命令 QOS

26. 链路追踪 Tracing

...
一共 60 篇++

SpringBoot2.x集成Sharding-JDBC实现分库分表 概述 ShardingSphere,它由Sharding-JDBC、Sharding-Proxy和Sharding-Sidecar(计划中)这3款相互独立的产品组成。定位为轻量级Java框架。其实就是一个增强版的JDBC驱动,完全兼容JDBC和各种ORM框架。内部改写了SQL的添加和查询规则。适用于任何基于Java的ORM框架,如:JPA, Hibernate, Mybatis, Spring ... 阅读详情

相关推荐

(六)springboot + mybatis plus实现多表联查分页3.X版本

注明 : 上两篇文章我们讲解了springboot+mybatis-plus对于单表的CRUD和条件构造器的使用方法,但是对于我们的实战项目中多表联查也是经常会出现的。今天我们就来说下怎么在springboot+MP模式下实现多表联查并分页。 项目源码下载位置 | gitee MP推荐使用的是一种苞米豆团队自己封装好的分页插件,也就是PaginationInterceptor分页拦截器,那么下面我...

QingFeng-Li的博客 4万+

springBoot使用通用mapper和分页助手

1(使用).写代码之前,我们需要了解,为什么我们要使用通用mapper?以及分页助手?    因为考虑到springBoot整合myBatis每次都要写增删查改重复的的代码,所以我们 使用通用mapper来解决这个问题,同时用时分页助手来辅助开发,  2(环境).使用通用助手之前,我们需要搭建springBoot基本环境,如果没有搭建的话,请搭建好基本环境再来 ,也就俩步(1.拷

qq_40794266的博客 6432

SpringBoot2.x系列教程(五十七)SpringBoot集成mybatis-plus及分页

前面我们将了Spring Boot集成Mybatis相关的操作,而在Mybatis-plus则是基于Mybatis进行了更加丰富的基础功能提供和封装,比如预置了大量的默认方法以及分页组件。 比如其中提供的BaseMapper,用于其他业务Mapper的集成接口变定义了如下常见的功能的接口: public interface BaseMapper<T> extends Mapper&lt...

程序新视界 1907

Springboot项目内自定义分页Mapper

Mapper类的写法需要注意了,一是在wrapper参数前加上,@Param(Constants.WRAPPER)注解。{ew.customSqlSegment},我这里用的是$而不是#,因为如果是#{参数名}的方式,编译出来会变成"内容",会带上双引号,这样就不对了。controller的书写方式,主要是Page对象的泛型要写查询对应返回的实际对象类型,wrapper的泛型只要是条件对应的那张表明即可。下面是查询返回的类的对象信息,简单说就是双表联查综合得到的信息。Service接口写法。

weixin_44302086的博客 798

SpringBoot第26讲:SpringBoot集成MySQL - MyBatis PageHelper分页

前文中,我们展示了Spring Boot与MyBatis的集成,但是没有展示分页实现。本文是SpringBoot第26讲,专门介绍分页相关知识体系和基于MyBatis的物理分页PageHelper

Jet_qi的博客 816

MyBatis基于Spring-boot集成通用Mapper以及pagehelper分页插件

MyBatis基于Spring-boot集成通用Mapper以及pagehelper分页插件,含单元测试、SQL脚本;减少Mybatis SQL的编写

SpringBoot实现分页

简单介绍SpringBoot的几种常用分页手段。

weixin_51506327的博客 3384

spring-boot-集成mybatis带分页page

# Spring Boot 集成 MyBatis, 分页插件 PageHelper, 通用 Mapper ## 项目依赖 ```xml <!--mybatis--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <!--mapper--> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <!--pagehelper--> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> ``` ## Spring DevTools 配置 在使用 DevTools 时,通用Mapper经常会出现 class x.x.A cannot be cast to x.x.A。 同一个类如果使用了不同的类加载器,就会产生这样的错误,所以解决方案就是让通用Mapper和实体类使用相同的类加载器即可。 DevTools 默认会对 IDE 中引入的所有项目使用 restart 类加载器,对于引入的 jar 包使用 base 类加载器,因此只要保证通用Mapper的jar包使用 restart 类加载器即可。 在 `src/main/resources` 中创建 META-INF 目录,在此目录下添加 spring-devtools.properties 配置,内容如下: ```properties restart.include.mapper=/mapper-[\\w-\\.]+jar restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar ``` 使用这个配置后,就会使用 restart 类加载加载 include 进去的 jar 包。 ## 集成 MyBatis Generator 通过 Maven 插件集成的,所以运行插件使用下面的命令: >mvn mybatis-generator:generate Mybatis Geneator 详解: >http://blog.csdn.net/isea533/article/details/42102297 ## application.properties 配置 ```properties #mybatis mybatis.type-aliases-package=tk.mybatis.springboot.model mybatis.mapper-locations=classpath:mapper/*.xml #mapper #mappers 多个接口时逗号隔开 mapper.mappers=tk.mybatis.springboot.util.MyMapper mapper.not-empty=false mapper.identity=MYSQL #pagehelper pagehelper.helperDialect=mysql pagehelper.reasonable=true pagehelper.supportMethodsArguments=true pagehelper.params=count=countSql ``` ## application.yml 配置 完整配置可以参考 [src/main/resources/application-old.yml](https://github.com/abel533/MyBatis-Spring-Boot/blob/master/src/main/resources/application-old.yml) ,和 MyBatis 相关的部分配置如下: ```yaml mybatis: type-aliases-package: tk.mybatis.springboot.model mapper-locations: classpath:mapper/*.xml mapper: mappers: - tk.mybatis.springboot.util.MyMapper not-empty: false identity: MYSQL pagehelper: helperDialect: mysql reasonable: true supportMethodsArguments: true params: count=countSql ``` 注意 mapper 配置,因为参数名固定,所以接收参数使用的对象,按照 Spring Boot 配置规则,大写字母都变了带横线的小写字母。针对如 IDENTITY(对应i-d-e-n-t-i-t-y)提供了全小写的 identity 配置,如果 IDE 能自动提示,看自动提示即可。 ## SSM集成的基础项目 >https://github.com/abel533/Mybatis-Spring ## MyBatis工具 http://www.mybatis.tk - 推荐使用 Mybatis 通用 Mapper3 https://github.com/abel533/Mapper - 推荐使用 Mybatis 分页插件 PageHelper https://github.com/pagehelper/Mybatis-PageHelper ## 作者信息 - 作者博客:http://blog.csdn.net/isea533 - 作者邮箱:abel533@gmail.com

通用Mapper 枚举类型转换处理

在application.properties中添加配置 枚举按简单类型处理,如果有枚举字段则需要加上该配置才会做映射 mapper.enum-as-simple-type = true 或者 mapper: enumAsSimpleType: true 在实体类的枚举字段加注解@ColumnType /** * 性别 男:MALE 女:FEMALE */ @ColumnType...

lucky_love816的博客 1299

ArcGIS小白必看:5分钟搞定shp矢量文件分割(附常见错误排查)

本文为ArcGIS新手详细解析了分割shp矢量文件的四种核心方法:裁剪工具、分割工具、按属性选择导出及ArcPy脚本自动化。重点强调了投影匹配等关键步骤,并提供了常见错误排查指南,帮助用户快速掌握矢量数据分割技巧,提升GIS数据处理效率。

h9j8k7l6m5n的博客 802

CentOS 7下Multipath多路径存储的实战配置与性能优化

本文详细介绍了在CentOS 7系统中配置与优化Multipath多路径存储的完整实战流程。从安装部署、核心配置文件解读,到性能调优与生产环境避坑指南,全面解析如何利用Device Mapper Multipath构建高可用、负载均衡的存储链路,提升存储系统可靠性与I/O性能。

weixin_29278805的博客 321

SpringBoot学习历程(九):SpringBoot2.X集成mybatis和pagehelper分页

SpringBoot学习历程(九):集成mybatis1. 引入相关依赖2. 增加datasource配置信息3. 创建用户信息类3.1 User.java3.2 UserMapper.java3.3 UserMapper.xml3.4 UserService.java3.5 UserController.java4. 启动类增加注解5. 启动进行测试 本人所用SpringBoot版本为2.1.9...

RabbitInTheGrass的博客 608

CSP-J 入门级第一轮认证 2025 详细解析

2025年CSP-J入门级第一轮认证模拟赛提供10套免费试题,含选择题与解析。选择题涉及计算机科学基础,如32位无符号整数最大值计算(约42.9亿,选A)、C++位运算(255&254=254,选B)、递归函数分析(calc(5)=6,选B)、哈夫曼树构造(带权路径长度186,选B)等。其他题目涵盖图论(有向图边数等于入度/出度和,选B)、组合数学(120种选法,选C)、布尔逻辑(选项C不恒等)、模运算周期性(f[2025]=6,选D)、C++字符串特性(支持string+char,选B)及引用传参

lan_in的博客 2947

Spring Boot2.x-08Spring Boot2.1.2 整合 Mybatis1.3.2 + 通用Mapper2.1.4 + PageHelper1.2.10 + Druid 1.1.10

文章目录概述整合 MyBatis整合 通用Mapper2.1.4及 PageHelper1.2.10添加依赖通用mapper 编写application.yml增加配置集成验证测试整合Druid (纯配置文件)添加依赖application.yml增加配置集成验证测试代码 概述 官方指导:https://github.com/abel533/MyBatis-Spring-Boot 不过版本较低,我...

小工匠 2万+

用Python实现斗地主游戏(终端版)

马上就要过年了 大家也都放假了吧 过年必不可少的活动 打牌! 今天带大家来写一份斗地主 (又是好多天没怎么更新,忙成狗啊) 那么实现一个斗地主呢 我们肯定要先完善卡牌系统 from collections import Counter import numpy as np import itertools def cmp_to_key(mycmp): 'Convert a cmp= function into a key= function' class K: def _

Miku_wx的博客 9858

Halcon棋盘格畸变矫正

通常我们使用的相机都是带有一定的畸变的,只是畸变的大小不同。对于我们常见的测量项目来说,对测量精度的要求很高,通常从相机镜头上进行优化,但是即使镜头优化或者成本原因,造成图像仍有一定的畸变时,我们就可是使用棋盘格标定板,进行畸变矫正。

m0_51559565的博客 3398

通用Mapper之TK Mybatis

推荐阅读此网站,用法和介绍全面超级详细:Mybatis通用mapper 通用mapper的特点 让开发者极其方便的使用MyBatis进行单表的增删改查,但是也仅仅支持单表操作,不支持通用的多表联合查询。 实现原理 作者的博客:通用mapper的实现原理 整合到项目中 参考上边的文档即可,楼主这里只记录相关jar包的maven地址 Spring Boot项目整合通用mapper的启动器:mappe...

CHENFU_ZKK的博客 1048

UR5 机械臂手眼标定(Eye-in-Hand)实战:OpenCV 求解 AX=XB,误差 < 2mm

本文详细介绍了UR5机械臂在Eye-in-Hand配置下的手眼标定实战,通过OpenCV实现高精度标定,最终达到误差小于2mm的工业级精度要求。文章涵盖了标定基础原理、环境搭建、数据采集策略、核心算法实现及误差分析与优化,为视觉机械臂的自主抓取提供了实用指南。

weixin_31476015的博客 297

mapper mysql 分页_SpringBoot集成MyBatis,分页插件PageHelper,通用Mapper

Spring Boot 1.5.1.RELEASEmybatis-spring-boot-startermapper-spring-boot-starterpagehelper-spring-boot-starter项目依赖org.mybatis.spring.bootmybatis-spring-boot-starter1.3.1tk.mybatismapper-spring-boot-star...

weixin_39593961的博客 135

某城商银行生产容器云平台详细设计方案分享及经验总结

AS3模式的CIS容器部署在K8S集群内,作为F5的控制器,CIS容器通过对K8S集群内Configmap资源进行监控,将Configmap资源中的内容转化为F5的配置,将配置推送给 F5 ,CIS容器还通过K8S标准的API接口完成业务发现和实时监听集群内Pod的变化,一旦Pod发生变化,相应的更新会及时推送给F5,并完成更新。容器技术发展非常迅速,现在应用大多以容器作为承载介质,前两年在容器云上承载的应用类型主要是Web类,随着容器云领域的不断发展,越来越多的应用类型将迁移至容器云,包括有状态应用。

qq_61890005的博客 862

ASPICE标准快速掌握「总目录」

欢迎大家来到雪云飞星的《ASPICE标准快速掌握》,开始前博主先列出本专栏学习的大纲,同时这也可以作为大家学习ASPICE协议知识点的参考。本专栏可以帮助大家快速掌握如何在项目中使用ASPICE,ASPICE的学习通常仅需要半天时间左右,掌握方法后完全就可以结合快查表来指导具体项目的质量提升了。

雪云飞星的博客 3013

Spring Boot 2.X 集成 Mybatis PageHelper 分页插件解决一对多分页查询问题

Spring Boot 2.X 集成 Mybatis PageHelper 分页插件解决一对多分页查询问题 每个项目中都会用到分页查询,这一技术具有高度的复用性,为了避免每次创建新项目时重新编写一边分页查询,或者因为项目的数据库更换而重新编写分页代码,将分页查询提取出来封装成专门的第三方库就显得十分必要。本文将介绍基于 Spring Boot 2.X 集成 Mybatis PageHelper 分页插件。

Mrqiang9001 1802

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

SpringBoot整合通用Mapper实战:从入门到精通,避坑指南与性能优化

在Java后端开发中,ORM框架是数据持久层的核心技术,它通过对象关系映射简化了数据库操作。MyBatis作为主流ORM框架,以其灵活性著称,但手动编写大量SQL语句仍显繁琐。通用Mapper(tk.mybatis)基于MyBatis,通过注解和接口继承自动生成SQL,显著提升了单表CRUD的开发效率。其技术价值在于遵循约定大于配置的原则,减少了重复代码,但同时也引入了动态SQL生成和复杂查询支持等挑战。在实际应用场景中,开发者常面临配置细节、方法误用及性能问题。本文聚焦于通用Mapper的高频使用场景,深

weixin_34199405的博客 422

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 分布式做系统 Elastic-Job-Lite 源码分析 —— 作业初始化
下一篇: 哪个更快:Java 堆还是本地内存
公众号-芋道源码
博客等级 码龄10年 1639粉丝 377原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值