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
    评论
要使用MyBatis-Plus生成XML配置的代码,你需要进行以下配置: 1. 在application.properties文件中,配置MyBatis-Plus的相关属性,如开启SQL日志、映射下划线字段为驼峰格式等。\[1\] 2. 创建一个配置类(如MyBatisPlusConfig),使用@Configuration注解标记为配置类,并使用@MapperScan注解指定要扫描的mapper文件夹。在该配置类中,你可以注册乐观锁插件和逻辑删除组件。\[2\] 3. 创建另一个配置类(如MybatisConfig),同样使用@Configuration注解标记为配置类,并使用@EnableTransactionManagement注解开启事务管理。在该配置类中,你可以配置MyBatis-Plus的分页插件。\[3\] 通过以上配置,你就可以使用MyBatis-Plus生成XML配置的代码了。 #### 引用[.reference_title] - *1* *3* [spring boot 2 整合 mybatis-plus 3.5.1,mybatis-plus-generator 自动生成代码](https://blog.csdn.net/bish326/article/details/123661864)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [MyBatis-Plus——代码自动生成器](https://blog.csdn.net/Huang_ZX_259/article/details/122540801)[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^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值