日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

关于mybatis中基本类型条件判断问题

發(fā)布時間:2025/7/14 59 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于mybatis中基本类型条件判断问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

今天繼續(xù)使用mybatis搭建我的網(wǎng)站,在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);

按照上述方式提供服務(wù)時會報如下錯誤:

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)

這是說我的參數(shù)中沒有g(shù)et方法?

據(jù)說這個是用ognl來判斷的 ,這個問題的解決方法在我看來只能用hashmap啦。

其實mybatis里有對這個進(jìn)行處理

只需要吧接口改成如下形式就ok啦:

int countByCate(@Param(value = "cate") int cate);

在參數(shù)中指定一下 param 。 大功告成,單元測試順利執(zhí)行。

據(jù)說mybatis要在下一個版本中去掉hashmap 大概就是想用這個東西來替代吧

?

轉(zhuǎn)載于:https://my.oschina.net/icoding/blog/632568

總結(jié)

以上是生活随笔為你收集整理的关于mybatis中基本类型条件判断问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。