1、mybatis的@Param()参数传递的问题,与JDK1.8的Optional的返回值问题。使用Optional与spring-data-jpa和mybatis有啥区别?

使用spring-data-jpa可以使用Optional<实体>,这样的返回不会出错。

但是Mybatis不行,返回值不能是 Optional<实体>,这样子会报错,字段也传入不到mapperxml中。

2、mybatis的传递参数为集合(set,list)的问题。

问题原因:

出错原因:collection写set,list或者collection,所以出错。

3、mybatis使用自定义的分页插件,查询记录条数,查询显示内容

public class PageResult<T> {
private int currentPage; private int pageSize; private int totalPages; private long totalCount; private List<T> content; public int getCurrentPage() {
return currentPage;
} public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
} public int getPageSize() {
return pageSize;
} public void setPageSize(int pageSize) {
this.pageSize = pageSize;
} public int getTotalPages() {
return totalPages;
} public void setTotalPages(int totalPages) {
int page= (int) (this.totalCount/pageSize);
if(this.totalCount%pageSize>0){
page++;
}
this.totalPages = page;
} public long getTotalCount() {
return totalCount;
} public void setTotalCount(long totalCount) {
this.totalCount = totalCount;
} public List<T> getLContent() {
return content;
} public void setContent(List<T> content) {
this.content = content;
}

 页面传递的参数: 

currentPage 当前页,pageSize每页的数据条数
pageResult.setCurrentPage(currentPage);
pageResult.setPageSize(pageSize);
计算有多少条记录count:select count(*) from 表
pageResult.setTotalCount(count);pageResult.setTotalPages(pageResult.getTotalPages()); 查询页面内容: select * from 表 where 条件
order by 字段 什么顺序(desc还是asc)limit #{currentPage},#{pageSize}
pageResult.setContent(页面内容)
返回pageResult即可。

Optional与Mybatis能否一起的更多相关文章

  1. Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件

    前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...

  2. 我最喜欢的Mybatis 3.5新特性!超实用!

    Mybatis 3.5 发布有段时间了,终于支持了 Optional ,这么实用的特性,竟然还没人安利……于是本文出现了. 新特性比较简单,但非常实用,因为能大量简化恶心的判空代码. WARNING ...

  3. Mapper XML Files详解

    扫扫关注"茶爸爸"微信公众号 坚持最初的执着,从不曾有半点懈怠,为优秀而努力,为证明自己而活. Mapper XML Files The true power of MyBatis ...

  4. springboot+springcloud集成jar

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  5. java:redis(java代码操作redis,实体类mapper生成器(generator))

    1.redis_demo Maven  ItemMapper.xml: <?xml version="1.0" encoding="UTF-8" ?> ...

  6. Springboot整合MybatisPlus(超详细)完整教程~

    新建springboot项目 开发工具:idea2019.2,maven3 pom.xml <dependency> <groupId>org.springframework. ...

  7. JavaWeb-JDBC-Mybatis-Junit-Maven-Lombok

    Java与数据库 初识JDBC JDBC是什么? JDBC英文名为:Java Data Base Connectivity(Java数据库连接),官方解释它是Java编程语言和广泛的数据库之间独立于数 ...

  8. IDEA 中生成 MyBatis 逆向工程实践

    IDEA 逆向 MyBatis 工程时,不像支持 Hibernate 那样有自带插件,需要集成第三方的 MyBatis Generator. MyBatis Generator的详细介绍 http:/ ...

  9. 从头开始搭建一个mybatis+postgresql平台

         最近有个项目的数据库使用postgresql,使用原生态的mybatis操作数据,原生态的没什么不好,只不过国内有个tk.mybatis的工具帮助我们做了很多实用的事情,大多数情况下我们需要 ...

随机推荐

  1. Map获取key值

    有两种方法 public static void test4(){ Map<String, Object> map = new HashMap<>(); map.put(&qu ...

  2. 【CV】ICCV2015_Describing Videos by Exploiting Temporal Structure

    Describing Videos by Exploiting Temporal Structure Note here: it's a learning note on the topic of v ...

  3. 同步手绘板——PC端实现画板

    同步显示上设想通过bitmap传值再在web端显示,查阅资料发现有点难以实现,所以在web也生成一个画板,实现与android端类似功能,由android传递路径集合到web端显示.

  4. UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现(转)

    UML图中类之间的关系:依赖,泛化,关联,聚合,组合,实现   类与类图 1) 类(Class)封装了数据和行为,是面向对象的重要组成部分,它是具有相同属性.操作.关系的对象集合的总称. 2) 在系统 ...

  5. 第三个Sprint ------第九天

    四则运算APP内侧: 1将APP安装包apk发到QQ群(班群),让自己班的同学率先体检.通过同学们的反馈.及时处理好bug,快速迭代. 2将APP下载链接发到微信朋友圈,QQ空间,让其他学校的同学也体 ...

  6. Neo4j初探

    neo4j-desktop-win64 exe https://neo4j.com/download-thanks-desktop/?edition=desktop&flavour=winst ...

  7. Eclipse布局问题小记

    当Eclipse的Debug,Console(简称工具条)页面被误操作到占据整行时,通过点击工具条的非选项卡部分,然后向代码区域拖动,即可得恢复非单独行模式.

  8. Activiti中子流程:SubProcess,CallActiviti的区别

    子流程:SubProcess,CallActiviti的区别 https://community.alfresco.com/thread/221771-call-activiti-vs-subproc ...

  9. ASP.NET MVC与WebForm对比

    MVC优点:1.分离更彻底,分层清晰,易于维护和扩展.2.验证更加方便快捷.3.无ViewState,页面更加干净4.路由更容易定义url,对SEO比较好.5.强类型VIEW实现,更安全高效. Web ...

  10. CRM模块