Mybatis 返回值配置理解

您所在的位置:网站首页 decimal对应的实体类 Mybatis 返回值配置理解

Mybatis 返回值配置理解

2024-07-10 21:20| 来源: 网络整理| 查看: 265

目录 前提1. 返回整形数值2. 返回值 BigDecimal 浮点数 金额类型3. 返回指定实体类格式的 List 数组参考链接

前提

Mybatis报错: A query was run and no Result Maps were found for the Mapped Statement

mybatis中的所有查询标签,都必须返回resultType或者resultMap的值,否则就会报如上错误的,其实仔细看看因为报错原因的意思就好了

1. 返回整形数值

TestMapper.xml 演示:

SELECT COUNT(1) FROM test_table

Java 调用演示:

@Autowired private TestMapper testMapper; Integer mycount = testMapper.getReturnNum(); 2. 返回值 BigDecimal 浮点数 金额类型

TestMapper.xml 演示:

SELECT IFNULL(SUM(mymoney), 0.00) FROM test_table

Java 调用演示:

@Autowired private TestMapper testMapper; Integer mycount = testMapper.getReturnAmount(); 3. 返回指定实体类格式的 List 数组

TestMapper.xml 演示:

SELECT * FROM test_table

Java 调用演示:

import com.test.entity.MyEntity; @Autowired private TestMapper testMapper; List myList = testMapper.getReturnList(); 参考链接

Mybatis报错: A query was run and no Result Maps were found for the Mapped Statement



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3