场景:外部系统提供的视图,数据库表goods的品牌编码字段名是brandCode,没有下划线不符合命名规范。
如果在动态sql里直接写 brandCode,那就会报错:org.postgresql.util.PSQLException: 错误: 字段 "brand_code" 不存在,
MyBatisPlus框架会自动把brandCode转换为brand_code。
(项目用的不是MyBatisPlus框架,把动态sql里的 brandCode 改成 "brandCode" 不报错可以查出数据)
直接在DBeaver里查询:
select "brandCode" from goods g //不报错,能查出数据
select brandCode from goods g
//报错 :错误: 字段 "brandcode" 不存在 Hint: 也许您想要引用列"g.brandCode"。
解决方法:老实把数据库表goods的品牌编码字段名改成brand_code
<select id="getGoods" resultMap="BaseResultMap">
select
id,
name,
storage,
goodstype,
count,
remark,
target_value,
target_value_string,
target_big,
data_status,
brandCode
from goods
where data_status = '0'
<if test="param.name !=null and param.name !=''">
and name = #{param.name}
</if>
</select>
MyBatisPlus框架会自动把动态sql里查询的表中的字段brandCode转换为brand_code,导致报错
于 2024-07-30 21:44:22 首次发布