學習ssm框架——Mybatis版本問題解決方案(一)

前幾天搭建了ssm框架準備開發後端,今天寫mapper時遇到個棘手的問題-寫select語句時發現入參報錯總是提示找不到username,而且錯誤信息裏面有四個參數,而我的入參只有兩個,貼出源代碼和錯誤信息。

<select id="selectUserByNameAndPassword" parameterType="String" resultType="po.User">     
    select * from user where username = #{username} and password = #{password}  
</select>

Mybatis參數問題
報錯信息


然後經過一番折騰在網上找到解決方案,將變量改成參數形式0,1或者加上jdbcType,代碼如下

<select id="selectUserByNameAndPassword" parameterType="String" resultType="po.User">     
    select * from user where username = #{0} and password = #{1}  
</select>

And

<select id="selectUserByNameAndPassword" parameterType="String" resultType="po.User">     
    select * from user where username = #{username, jdbcType=VARCHAR} and password = #{password, jdbcType=VARCHAR}  
</select>

報錯同上。


此時就很難受了,看源碼debug。。。
偶然間查到了可能是版本問題,然後嘗試了以下解決方案搞定

<select id="selectUserByNameAndPassword" parameterType="String" resultType="po.User">     
    select * from user where username = #{arg0} and password = #{arg1}  
</select>

最後貼上碼雲項目地址

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章