倔强的姑娘^o^
2021-04-23 14:38
采纳率: 100%
浏览 72
已采纳

mybatis 3.5.0 版本resultMap无法映射问题

1、版本

mybatis:3.5.0,mybatis-spring:2.0.6,jdk :1.8

2、问题

日志sql已经查询出来了

但是在后台断点处无法接收到查询出来的值

在sql里面对字段起了别名,使用resultMap进行映射无法正常设值,但是将resultMap改成了resultType就好用了

附上mybatis 代码

<resultMap id="BaseResultMap" type="com.stock.capital.enterprise.controlRules.dto.ControlRulesDto">
        <id column="id" property="id" jdbcType="VARCHAR" />
        <result column="trade_compliance_type" property="tradeComplianceType" jdbcType="VARCHAR" />
        <result column="company_id" property="companyId" jdbcType="VARCHAR" />
        <result column="compliance_id" property="complianceId" jdbcType="VARCHAR" />
        <result column="rule_status" property="ruleStatus" jdbcType="VARCHAR" />
        <result column="rule_number" property="ruleNumber" jdbcType="VARCHAR" />
        <result column="instructions" property="instructions" jdbcType="VARCHAR" />
        <result column="openAndAll" property="openAndAll" jdbcType="VARCHAR" />
        <result column="forcibly_prohibited_transactions" property="forciblyProhibitedTransactions" jdbcType="VARCHAR" />
        <result column="openPersonNum" property="openPersonNum" jdbcType="INTEGER" />
        <result column="allPersonNum" property="allPersonNum" jdbcType="INTEGER" />
        <result column="effect_start" property="effectStart" jdbcType="DATE" />
        <result column="invalid_end" property="invalidEnd" jdbcType="DATE" />
        <result column="company_name" property="companyName" jdbcType="VARCHAR" />
        <result column="company_code" property="companyCode" jdbcType="VARCHAR" />
    </resultMap>
<select id="queryControlRules"     parameterType="com.stock.capital.enterprise.controlRules.dto.ControlRulesDto" resultMap="BaseResultMap">
select totalCom.*,elseCom.ruleStatus,elseCom.forciblyProhibitedTransactions
from 
(
select s.zh_name as companyName,
s.`company_code` AS `companyCode`,
s.`create_time` AS `createTime`,
s.id AS `companyId`,
mm.id as complianceId,
mm.`trade_compliance_type` AS `tradeComplianceType`,
mm.`instructions` AS `instructions`,
mm.rule_number as ruleNumber,
mm.`effect_start` AS `effectStart`,
mm.`invalid_end` AS `invalidEnd`
,(
SELECT count(1) 
FROM edit_controls AS E 
inner join sa_person AS P 
on (P.id=E.person_id)
 where ( (E.if_effect = '1' )
 and (E.compliance_id = mm.id)
 and (E.company_id =s.id)
and (P.shareholder_status='Y'))
) as openPersonNum
,(
SELECT count(1) 
from edit_controls AS E 
join sa_person AS P 
on ( P.id=E.person_id )
where ( (E.compliance_id = mm.id )
and (E.company_id =s.id)
and (P.shareholder_status='Y')
)) as allPersonNum

from sa_company s
,(
select t.*
from trade_compliance t
left join total_rule tr 
on tr.rule_number = t.rule_number
where tr.`status`='1'
) as mm
where s.id!='96392852564612838'

) as totalCom
left join 
(
select 
scm.compliance_id as complianceId,
sc.id as companyId,
scm.rule_status as ruleStatus,
case scm.forcibly_prohibited_transactions when 1 then 1
else 0 end as forciblyProhibitedTransactions
from sa_company_compliance_map scm
left join sa_company sc
ON((`sc`.`id` = `scm`.`company_id`))
) as elseCom
on totalCom.companyId = elseCom.companyId
and totalCom.complianceId = elseCom.complianceId
<where>
<if test="companyName != null and companyName != ''"> 
totalCom.companyCode LIKE CONCAT('%', #{companyName}, '%') 
OR totalCom.companyName LIKE CONCAT('%', #{companyName}, '%') 
</if>
</where>
order by totalCom.createTime DESC,companyId DESC,totalCom.ruleNumber ASC
</select>

初步考虑是mybatis 版本之间的冲突,改了半天还是不行

有大佬知道为什么,怎么解决吗?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • clever101 2021-04-24 12:49
    已采纳
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • damoneric_guo 2021-04-23 14:42

    你查出来的数据别起别名啊

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题