mybaits错误解决:There is no getter for property named ... in 'class java.lang.String'

在使用mybaitis传参数的时候,如果仅传入一个类型为String的参数,那么在 xml文件中应该使用_parameter来代替参数名。

正确的写法:

    <select id="getDeptInfo" parameterType="String" resultType="com.gskdht.pushmessage.model.DeptInfo">
        SELECT DEPT_ID,PARENT_ID,DEPT_NAME,DEPT_LEVEL from PARA_DEPT 
        <where>
            <if test="_parameter != '1'.toString() ">
                PARENT_ID = #{_parameter}
            </if>
        </where>

    </select>

错误的写法:

    <select id="getDeptInfo" parameterType="String" resultType="com.gskdht.pushmessage.model.DeptInfo">
        SELECT DEPT_ID,PARENT_ID,DEPT_NAME,DEPT_LEVEL from PARA_DEPT 
        <where>
            <if test="parentId != '1'.toString() ">
                PARENT_ID = #{parentId}
            </if>
        </where>

    </select>

也可以在mapper的接口中,给这个方法的参数加上@Param(value=“parentId”),这样就能在.xml中使用#{parentId} 了。

如:public List<DeptInfo> getDeptInfo(@Param("parentId") String parentId)

这样也是可以的。
 

猜你喜欢

转载自blog.csdn.net/weixin_43552143/article/details/87391152
今日推荐