错误为:There is no getter for property named 'name' in 'class java.lang.String'
两种解决方式:
第一种:mybatis采用ognl解析参数,因此sql语句中
<select id="queryPoetriesList" resultMap="poetsMapper" parameterType="String">
select id,name from Poets
<where>
<if test="name!=null and !"".equals(name.trim())">
and name like '%' #{name} '%'
</if>
</where>
</select>
#{name}无法解析,可以使用
_parameter 代替 name
<select id="queryPoetriesList" resultMap="poetsMapper" parameterType="String">
select id,name from Poets
<where>
<if test="_parameter !=null and !"".equals(_parameter .trim())">
and name like '%' #{_parameter } '%'
</if>
</where>
</select>
第二种方法:在映射器接口上添加注解:
public List<Poets> queryPoetriesList(@Param(value="name")String name);
xml中则可以同之前写法
<select id="queryPoetriesList" resultMap="poetsMapper" parameterType="String">
select id,name from Poets
<where>
<if test="name!=null and !"".equals(name.trim())">
and name like '%' #{name} '%'
</if>
</where>
</select>