日期:2014-05-20  浏览次数:20622 次

用过ibatis和mybatis的朋友请进
mybatis参数问题:
-------------------------------
XML code

<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
------解决方案--------------------
探讨
好像用value

------解决方案--------------------
ibatis 没有if,不知道Mybatis
ibatis应该为:
XML code
<isNotEmpty prepend="and" property="classid">
                ka_classid = #classid#
            </isNotEmpty>

------解决方案--------------------
又是你啊!首先,参数是可以这么传的,parameterType="java.lang.String"
#{classid}是否和你 传入的参数名称一样?
在确认下,绝对可以是你那样传的,调试下,看看是否类型错误!
------解决方案--------------------
无能为力了,自己多测测吧,其实大多数问题还是只能靠自己