Mybatis之映射实体类中不区分大小写

做项目时候遇到一个Bug,实体类中有两个字段,例如(addTime,addtime),进行查询搜索会发生神奇的事情

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.runlin.jetta.mapper.JettaUpgradeLogMapper">
  <resultMap id="BaseResultMap" type="cn.runlin.jetta.entity.JettaUpgradeLog">
    <id column="upgrade_id" jdbcType="INTEGER" property="upgradeId" />
    <result column="task_id" jdbcType="INTEGER" property="taskId" />
    <result column="task_name" jdbcType="VARCHAR" property="taskName" />
    <result column="task_version" jdbcType="VARCHAR" property="taskVersion" />
    <result column="project_id" jdbcType="INTEGER" property="projectId" />
    <result column="project_name" jdbcType="VARCHAR" property="projectName" />
    <result column="project_type" jdbcType="TINYINT" property="projectType" />
    <result column="dealer_id" jdbcType="INTEGER" property="dealerId" />
    <result column="dealer_name" jdbcType="VARCHAR" property="dealerName" />
    <result column="service_code" jdbcType="VARCHAR" property="serviceCode" />
    <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
    <result column="addtime" jdbcType="INTEGER" property="addtime" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="reasonname" jdbcType="VARCHAR" property="reasonname" />
  </resultMap>
  <sql id="Base_Column_List">
    upgrade_id, task_id, task_name, task_version, project_id, project_name, project_type, 
    dealer_id, dealer_name, service_code, add_time, addtime
  </sql>
  //映射到实体类 而不使用xml文件中的BaseResultMap
  <select id="getJettaUpgradeLogList" resultType="cn.runlin.jetta.entity.JettaUpgradeLog" parameterType="Map">
	  select
	  jul.upgrade_id, task_id, task_name, task_version, project_id, project_name, project_type, 
      dealer_id, dealer_name, service_code, add_time, status, reasonname
	  from jetta_upgrade_log jul
	  LEFT OUTER JOIN jetta_upgrade_log_status juls
	  ON jul.upgrade_id=juls.upgrade_id
	  LEFT OUTER JOIN jetta_status_code jsc
	  ON juls.status_id= jsc.rid
	  <where>
			<if test="serviceCode != null and serviceCode !='' ">
				AND jul.service_code like concat("%",#{serviceCode},"%")
			</if> 
			<if test="dealerName != null and dealerName !='' ">
				AND jul.dealer_name like concat("%",#{dealerName},"%")
			</if>
			<if test="taskVersion != null and taskVersion !='' ">
				AND jul.task_version like concat("%",#{taskVersion},"%")
			</if>
			<if test="status != null and status !='' ">
				AND juls.status like concat("%",#{status},"%")
			</if>
	  </where>
  </select>
  
</mapper>

在这里插入图片描述
会报addTime是时间戳类型,不能转换成INTEGER类型的问题。原因就是mybatis映射实体类之后,不能区分大小写,而造成字段类型对应错误的问题

解决办法:把映射实体类变成映射到xml中所设置的resultMap,就可以解决这个问题

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.runlin.jetta.mapper.JettaUpgradeLogMapper">
  <resultMap id="BaseResultMap" type="cn.runlin.jetta.entity.JettaUpgradeLog">
    <id column="upgrade_id" jdbcType="INTEGER" property="upgradeId" />
    <result column="task_id" jdbcType="INTEGER" property="taskId" />
    <result column="task_name" jdbcType="VARCHAR" property="taskName" />
    <result column="task_version" jdbcType="VARCHAR" property="taskVersion" />
    <result column="project_id" jdbcType="INTEGER" property="projectId" />
    <result column="project_name" jdbcType="VARCHAR" property="projectName" />
    <result column="project_type" jdbcType="TINYINT" property="projectType" />
    <result column="dealer_id" jdbcType="INTEGER" property="dealerId" />
    <result column="dealer_name" jdbcType="VARCHAR" property="dealerName" />
    <result column="service_code" jdbcType="VARCHAR" property="serviceCode" />
    <result column="add_time" jdbcType="TIMESTAMP" property="addTime" />
    <result column="addtime" jdbcType="INTEGER" property="addtime" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="reasonname" jdbcType="VARCHAR" property="reasonname" />
  </resultMap>
  <sql id="Base_Column_List">
    upgrade_id, task_id, task_name, task_version, project_id, project_name, project_type, 
    dealer_id, dealer_name, service_code, add_time, addtime
  </sql>
  //映射到xml的BaseResultMap
  <select id="getJettaUpgradeLogList" resultMap="BaseResultMap" parameterType="Map">
	  select
	  jul.upgrade_id, task_id, task_name, task_version, project_id, project_name, project_type, 
      dealer_id, dealer_name, service_code, add_time, status, reasonname
	  from jetta_upgrade_log jul
	  LEFT OUTER JOIN jetta_upgrade_log_status juls
	  ON jul.upgrade_id=juls.upgrade_id
	  LEFT OUTER JOIN jetta_status_code jsc
	  ON juls.status_id= jsc.rid
	  <where>
			<if test="serviceCode != null and serviceCode !='' ">
				AND jul.service_code like concat("%",#{serviceCode},"%")
			</if> 
			<if test="dealerName != null and dealerName !='' ">
				AND jul.dealer_name like concat("%",#{dealerName},"%")
			</if>
			<if test="taskVersion != null and taskVersion !='' ">
				AND jul.task_version like concat("%",#{taskVersion},"%")
			</if>
			<if test="status != null and status !='' ">
				AND juls.status like concat("%",#{status},"%")
			</if>
	  </where>
  </select>
  
</mapper>

解决问题
在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微微笑再加油

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值