当前位置: 代码迷 >> J2EE >> 用过ibatis跟mybatis的朋友请进
  详细解决方案

用过ibatis跟mybatis的朋友请进

热度:5307   发布时间:2013-02-25 21:41:12.0
用过ibatis和mybatis的朋友请进
mybatis参数问题:
-------------------------------------------------------------------

<select id="countForToday" resultType="int" parameterType="string">
  select count(*) from knowledgearticle where ka_date = current_date
  <if test="classid!=null and classid != ''">
   and ka_classid = #{classid}
  </if>
</select>

-------------------------------------------------------------------
如上参数是一个string类型的字符串,运行时会报错:
ReflectionException: There is no getter for property named 'classid' in 'class java.lang.String'

这是个字符串不是实体啊,哪有getter for property named 'classid' ,晕...

疑惑:在select中如何用这个传入的string参数? 没有名字啊,不像实体一样,我这里用的classid随便取的,叫id效果也是一样的,好像不能代表传入的那个字符串
请问各位高手,mybatis是怎样处理这种情况的? 怎样处理单个参数在下面的引用?
好像用value无能为力了,自己多测测吧,其实大多数问题还是只能靠自己又是你啊!首先,参数是可以这么传的,parameterType="java.lang.String"
#{classid}是否和你 传入的参数名称一样?
在确认下,绝对可以是你那样传的,调试下,看看是否类型错误!
引用:
好像用value

可以传入个Object参数 里面有个属性为classid 提供set getibatis 没有if,不知道Mybatis
ibatis应该为:
<isNotEmpty prepend="and" property="classid">
                ka_classid = #classid#
            </isNotEmpty>
  相关解决方案