resultMap 可以接收全字段,resultType 接收部分字段为null

1.首先说一下原因:

因为resultMap  是在当前xml声明配置的,如下,对于每个字段的列和接收的属性都匹配过,所以可以一一对应拿到数据

<resultMap id="BaseResultMap" type="com.gdlt.cloud.entity.DtTask">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="project_id" jdbcType="INTEGER" property="projectId" />
    <result column="is_delete" jdbcType="INTEGER" property="isDelete" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_id" jdbcType="INTEGER" property="createId" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="update_id" jdbcType="INTEGER" property="updateId" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="task_data" property="taskData" typeHandler="com.gdlt.cloud.utils.ObjectJsonHandler"/>
  </resultMap>

然而 resultType  跟的是一个对象,当你没有配置驼峰属性的时候,对于数据库下划线的数据,如:project_id 往往是接不到的,大概就是这样的原因,而对于像id这样的单词是可以接收的。

所以想要可以接收驼峰,配置一下mybatis-config.xml 配置文件,

内容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="mapUnderscoreToCamelCase" value="true" />

    </settings>
</configuration>

我用的是springboot框架,所以,需要在application.properties 里面引入该配置文件,如下:

mybatis.config-location=classpath:/mybatis/mybatis-config.xml

如果你用的别的框架呢,就自行百度一下引入配置文件的方法吧,配置好驼峰之后,就可以接收数据了,没问题。 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在MyBatis中,resultTyperesultMap都是用于查询结果映射的方式。 resultType是直接指定查询结果的类型。它可以是一个基本类型(比如String、Integer等),也可以是一个自定义的实体类。当使用resultType时,MyBatis会根据查询结果的字段名和实体类的属性名进行自动映射。 resultMap则是对外部ResultMap的引用。它是一种更加灵活和可重用的方式,可以定义在Mapper文件中,以供多个查询语句共享。resultMap通过映射规则,将查询结果的列和实体类的属性进行映射。 所以,resultTyperesultMap的区别在于: - resultType适用于简单的查询结果映射,通过指定查询结果的类型来进行自动映射。 - resultMap适用于复杂的查询结果映射,通过外部ResultMap的引用来进行映射,并可以定义更加灵活和可重用的映射规则。 总结起来,resultType适用于简单的查询,而resultMap适用于复杂的查询,并且可以提供更灵活的映射规则。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [resultMapresultType的区别](https://blog.csdn.net/LMY0210/article/details/128238290)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [MyBatis中关于resultTyperesultMap的区别介绍](https://download.csdn.net/download/weixin_38717031/12793901)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值