mybatis加Spring项目: 解决There is no getter for property named '***' in 'class java.lang.String'问题

时间:2022-08-08 17:09:06

使用mybatis映射mysql数据库时,传入参数为'status',运行报错为:There is no getter for property named 'status' in 'class java.lang.String

使用'#'作为mybatis的映射标识运行可以通过,但是'#'不能实现SQL串的拼接,'$'符号是“替换”,可以实现SQL的拼接,用$替代#之后以为万事大吉,运行时我们就会发现我们错了!

映射配置文件代码如下:

<select id="selectYLZ" resultMap="BaseResultMap" parameterType="java.lang.String">
select
<include refid="Base_Column_List" />
from tb_trunover_info where flag="A" and STATUS in(${status})
order by id ASC
</select>


其他层中代码写好DAO及Service发布 运行之后出现如下错误:

mybatis加Spring项目: 解决There is no getter for property named '***' in 'class java.lang.String'问题

 

经查找原因后发现不能将参数设为bean里的名称,如果传入类型为String类型,则参数需统一修改为 '_parameter',修改后的sql语句如下(不管你的参数是什么,都要改成"_parameter",否则会出错,)

 

更改之后的mybatis配置xml文件代码片段如下:

  <select id="selectYLZ" resultMap="BaseResultMap" parameterType="java.lang.String">
select
<include refid="Base_Column_List" />
from tb_trunover_info where flag="A" and STATUS in(${_parameter})
order by id ASC
</select>


DAO层的传入参数名称不用更改,直接与部署运行即可得到正确结果。