在整合mybatis和mybatis-plus的時候發(fā)現(xiàn)一個小坑,單獨使用mybatis,配置別名如下:
#配置映射文件中指定的實體類的別名
mybatis.type-aliases-package=com.jk.entity
XML映射文件如下:
<update id="update" parameterType="student">
update student
<set>
<if test="name!=null and name!=''">
name=#{name}
</if>
<if test="gender!=null and gender!=''">
gender=#{gender}
</if>
<if test="classname!=null and classname!=''">
classname=#{classname}
</if>
</set>
where id=#{id}
</update>
單元測試發(fā)現(xiàn)沒有問題
添加mybatis-plus依賴后,單元測試報錯:
顯示無法解析XML映射文件中的student
解決辦法:要把配置文件里的別名配置改成mybatis-plus的配置,如下:文章來源:http://www.zghlxwxcb.cn/news/detail-850452.html
#配置映射文件中指定的實體類的別名
mybatis-plus.type-aliases-package=com.jk.entity
區(qū)別文章來源地址http://www.zghlxwxcb.cn/news/detail-850452.html
到了這里,關(guān)于mybatis-plus與mybatis同時使用別名問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!