<select id="findUserById" parameterType="int" resultType="User"> select * from user1 <where> <if test="id != null and id != ''"> and id=#{id} </if> </where> </select>
在測試時報錯:There is no getter for property named 'id' in 'class java.lang.Integer'
問題分析:Mybatis默認采用ONGL解析參數,所以會自動采用對象樹的形式取integer.id值,引起報錯。
解決方法: public User findUserById(@Param("id")int id);說明參數值。