MyBatis中paramType中参数为String类型时报错异常。现在我们有⼀个dao层接⼝⽅法,
public Class findAllByName(String name);
建立制度那么对应l⽂件
<lect id="getAllByName" parameterType="string" resultType="Class">
lect * from class
<where>
<if test="name != null">
猴子的英文f_name like #{name}"%"深远的近义词
</if>
</where>
</lect>
小学青年教师>骑电动车
学习焦虑症⼀般来说,我们这样写对于其他类型来说是没有错的。但是如果传⼊参数为String的话就会抛出异常:
There is no getter for property named 'name' in 'class java.lang.Sting'
因为MyBatis要求如果参数为String的话,不管接⼝⽅法的形参是什么,在l中引⽤时需要改变为_parameter才能被识别:
<lect id="getAllByName" parameterType="string" resultType="Class">
lect * from class
<where>
无懈可击是什么意思
<if test="_parameter != null">
f_name like #{_parameter}"%"
</if>
</where>
</lect>
记住:这⾥的传⼊参数的两个都要修改为_paramter。 且传⼊参数有且仅有⼀个String的参数时才会有这种情况。好⽐说下⾯的这种情况你传⼊的是两个Sring参数,那么也就没有这种情况发⽣。
<lect id="getAllByName" resultType="Class">
lect * from class
<where>
<if test="param1 != null">
f_name like #{param1}"%"
</if>
<if test="param2 != null">
f_teacherName like #{param2}"%"
</if>
</where>
楼层选择
</lect>