关于mybatis中基本类型条件判断问题
生活随笔
收集整理的這篇文章主要介紹了
关于mybatis中基本类型条件判断问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
今天繼續使用mybatis搭建我的網站,在sql這塊有個問題
在sql的mapper中如下方式 <select id="countByCate" parameterType="int" resultType="int"> select count(*) from article where <if test="cate!=0"> cate = #{cate} and </if> deletetype=0; </select> 接口方法 :int countByCate(int cate);按照上述方式提供服務時會報如下錯誤:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'cate' in 'class java.lang.Integer' at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)at $Proxy11.selectOne(Unknown Source)at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:160)at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:95)at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)at $Proxy12.countByCate(Unknown Source)這是說我的參數中沒有get方法?
據說這個是用ognl來判斷的 ,這個問題的解決方法在我看來只能用hashmap啦。
其實mybatis里有對這個進行處理
只需要吧接口改成如下形式就ok啦:
int countByCate(@Param(value = "cate") int cate);在參數中指定一下 param 。 大功告成,單元測試順利執行。
據說mybatis要在下一個版本中去掉hashmap 大概就是想用這個東西來替代吧
?
轉載于:https://my.oschina.net/icoding/blog/632568
總結
以上是生活随笔為你收集整理的关于mybatis中基本类型条件判断问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx笔记系列(1)——Nignx的
- 下一篇: Go项目的目录结构