Mybatis-plus字段名称有下划线查询为null

在Mybatis-plus中自己写sql查询时,采用 resultType 做字段映射,带下划线的字段值查询不到。

	<select id="pageW_XKXMSJLXRSearch"
	        resultType="cjw.nic.niceasy.szyzgts.module.wy_ysgl.wy_01.wy_01_03.entity.W_XKXMSJLXR">
		SELECT temp.*
		FROM (
		SELECT t.*
		from w_xkxmsjlxr t
		INNER JOIN w_xkxmjbxx wx ON t.SSXKXMJBXX_ID = wx.ID AND wx.SCBJ = 0 and t.scbj = 0
		INNER JOIN s_xzqh sx ON sx.QHDM = #{qhdm} and wx.XZQHDM like CONCAT('%',sx.XJQHDMBDS,'%')
		) as temp
		${ew.customSqlSegment}
	</select>

原因分析:Mybatis-plus默认开启驼峰转换,ssxkxmjbxx_id 字段会被转换为 ssxkxmjbxxId ,自然查询不到。

解决方案:

(1)关闭 Mybatis-plus 驼峰转换,这样虽然能解决问题,但是会影响整个项目,得不偿失。

(2)采用 resultMap 做映射,自己写映射关系。

	<!-- 通用查询映射结果 -->
	<resultMap id="BaseResultMap" type="cjw.nic.niceasy.szyzgts.module.wy_ysgl.wy_01.wy_01_03.entity.W_XKXMSJLXR">
		<id column="ID" property="id"/>
		<result column="SSXTDM" property="ssxtdm"/>
		<result column="SSGCDM" property="ssgcdm"/>
		<result column="SSXKXMJBXX_ID" property="ssxkxmjbxx_id"/>
		<result column="SSGLDW_ID" property="ssgldw_id"/>
		<result column="GLDWLX" property="gldwlx"/>
		<result column="LXRJSDM" property="lxrjsdm"/>
		<result column="XM" property="xm"/>
		<result column="SZBM" property="szbm"/>
		<result column="ZW" property="zw"/>
		<result column="SJH" property="sjh"/>
		<result column="BGDH" property="bgdh"/>
		<result column="CZ" property="cz"/>
		<result column="YX" property="yx"/>
		<result column="LXDZ" property="lxdz"/>
		<result column="QQ" property="qq"/>
		<result column="BZ" property="bz"/>
		<result column="SCBJ" property="scbj"/>
		<result column="SCJL_ID" property="scjl_id"/>
		<result column="CJR_ID" property="cjr_id"/>
		<result column="CJSJ" property="cjsj"/>
		<result column="ZHXGR_ID" property="zhxgr_id"/>
		<result column="ZHXGSJ" property="zhxgsj"/>
	</resultMap>
	<select id="pageW_XKXMSJLXRSearch"
	        resultMap="BaseResultMap">
		SELECT temp.*
		FROM (
		SELECT t.*
		from w_xkxmsjlxr t
		INNER JOIN w_xkxmjbxx wx ON t.SSXKXMJBXX_ID = wx.ID AND wx.SCBJ = 0 and t.SCBJ = 0
		INNER JOIN s_xzqh sx ON sx.QHDM = #{qhdm} and wx.XZQHDM like CONCAT('%',sx.XJQHDMBDS,'%')
		) as temp
		${ew.customSqlSegment}
	</select>

ps: 采用 Mybaits-plus 代码生成器,免去写繁琐映射的烦恼!

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值