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是怎样处理这种情况的? 怎样处理单个参数在下面的引用?
-------------------------------------------------------------------<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是怎样处理这种情况的? 怎样处理单个参数在下面的引用?
解决方案 »
- ibatis 根据参数选择排序方式?
- 初学,请问这段函数什么意思
- war文件是什么文件?怎么使用啊
- 请大侠们帮帮忙~~~~~~~~~~~~~~
- spring 中出现了 there are 2 beans of type {com....}
- 兄弟们说说你们j2ee的开发平台
- ejb的事务处理
- 一个将jbuilder5和weblogic6.1集成开发EJB的问题,高手请进。
- httpclient cookie问题
- java request.getContentLength()输出有值,但request.getInputStream().read()确等于-1
- Hibernate抓取集合的集合
- 在MyEclipse中能运行的jQuery到Eclipse中不能运行。(拿分走人啦)
ibatis应该为:
<isNotEmpty prepend="and" property="classid">
ka_classid = #classid#
</isNotEmpty>
#{classid}是否和你 传入的参数名称一样?
在确认下,绝对可以是你那样传的,调试下,看看是否类型错误!
select count(*) from knowledgearticle where ka_date = current_date
<if test="classid!=null and classid != ''">
and ka_classid = #{classid}
</if>
</select>这是mybatis的写法,语法是没错的,mybatis没有property="classid"这种属性。
继续等高手...
<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} or ka_classid in (select kno_dbid from knowledgeclass where kno_parent = #{classid}))
</if>
</select> /**
* 今日更新的数量
*/
public int countForToday(String classid)
{
SqlSession session = sessionFactory.openSession();
try
{
int article = (Integer)session.selectOne("Article.countForToday",classid);
return article;
}
catch(Exception e)
{
log.error("获取今日更新的数量失败",e);
}
finally
{
session.close();
}
return 0;
}### Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'classid' in 'class java.lang.String'
and ka_classid = #{classid}
</if>改为 and ka_classid = #{classid}把标签去掉就可以了,标签是针对JAVABEAN或者MAP的,STRING不能用标签
<resultMap type="sExtension" id="sExtensionResult">
<result property="id" column="id" />
<result property="euid" column="euid"/>
<result property="extnum" column="extnum" />
<result property="extcode1" column="extcode1" />
<result property="extcode2" column="extcode2" />
<result property="extcode3" column="extcode3" />
<result property="addtime" column="addtime" />
</resultMap> 那么你的那个classid 在property中的值 与实体类保持一致就好,后面的colum不用多说你也该知道,就是数据库表中的列名,理所应当和你的数据库中的保持一致就好。试试吧,应该没问题。
and ka_classid = #{classid}
</if>