mybaits錯誤:There is no getter for property named 'id' in class 'java.lang.String'
阿新 • • 發佈:2019-02-11
在使用mybaitis傳引數的時候,如果僅傳入一個型別為String的引數,那麼在 xml檔案中應該使用_parameter來代替引數名。
錯誤的寫法:
<select id="isCargoBillNoExist" resultType="java.lang.Integer"> select count(1) from t_entry_cargo_receiver_info where 1=1 <if test="id != null" > and cargo_bill_no = #{id,jdbcType=VARCHAR} </if> </select>
正確的寫法 :
<select id="isCargoBillNoExist" resultType="java.lang.Integer"> select count(1) from t_entry_cargo_receiver_info where 1=1 <if test="_parameter != null" > and cargo_bill_no = #{_parameter,jdbcType=VARCHAR} </if> </select>
也可以在mapper的介面中,給這個方法的引數加上@Param(value=“id”),這樣就能在.xml中使用#{id,jdbcType=VARCHAR} 了。
如:
public Object getObjById(@Param("id)String id);
這樣我們就解決MyBatis找不到引數的問題啦。
大家如果有喜歡一起討論技術或者思維方面問題的可以加我的微信 a1024271896 ,我是夏天,和大家一起探索未來的旅途。